display the upgrade progress.
This commit is contained in:
parent
fb7dfdc800
commit
7917cc3eb5
|
@ -5,24 +5,30 @@
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
<title>Upgrade Framework</title>
|
<title>Upgrade Framework</title>
|
||||||
<base href="/" />
|
<base href="/" />
|
||||||
<link rel="stylesheet" href="https://www.oqtane.net/css/app.css">
|
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" />
|
||||||
|
<link rel="stylesheet" type="text/css" href="https://www.oqtane.net/css/app.css">
|
||||||
</head>
|
</head>
|
||||||
<body onload="forceWait()">
|
<body onload="refresh()">
|
||||||
<div>
|
<div>
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<h1 align="center">Please Wait... Upgrade In Progress...</h1>
|
<h1 align="center">Please Wait... Upgrade In Progress...</h1>
|
||||||
<p align="center">(this process can take a few minutes... please be patient)</p>
|
<p align="center">(this process can take a few minutes... please be patient)</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="w-50 mx-auto mt-5">
|
||||||
<div class="app-progress-indicator"></div>
|
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
|
||||||
|
<div class="progress-bar progress-bar-striped progress-bar-animated [PROGRESSCLASS]" style="width: [PROGRESS]%"></div>
|
||||||
|
</div>
|
||||||
|
<div class="fs-6 fst-italic mt-1">
|
||||||
|
[STATUS]
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function forceWait() {
|
function refresh() {
|
||||||
setInterval(function () {
|
setTimeout(function () {
|
||||||
window.location.href = "/";
|
window.location.href = "/?reload";
|
||||||
}, 120 * 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -31,10 +31,6 @@ namespace Oqtane.Updater
|
||||||
|
|
||||||
if (Directory.Exists(deployfolder))
|
if (Directory.Exists(deployfolder))
|
||||||
{
|
{
|
||||||
string log = "Upgrade Process Started: " + DateTime.UtcNow.ToString() + Environment.NewLine;
|
|
||||||
log += "ContentRootPath: " + contentrootfolder + Environment.NewLine;
|
|
||||||
log += "WebRootPath: " + webrootfolder + Environment.NewLine;
|
|
||||||
|
|
||||||
string packagename = "";
|
string packagename = "";
|
||||||
string[] packages = Directory.GetFiles(deployfolder, "Oqtane.Framework.*.Upgrade.zip");
|
string[] packages = Directory.GetFiles(deployfolder, "Oqtane.Framework.*.Upgrade.zip");
|
||||||
if (packages.Length > 0)
|
if (packages.Length > 0)
|
||||||
|
@ -42,15 +38,27 @@ namespace Oqtane.Updater
|
||||||
packagename = packages[packages.Length - 1]; // use highest version
|
packagename = packages[packages.Length - 1]; // use highest version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create upgrade log file
|
||||||
|
var logFilePath = Path.Combine(deployfolder, $"{Path.GetFileNameWithoutExtension(packagename)}.log");
|
||||||
|
if (File.Exists(logFilePath))
|
||||||
|
{
|
||||||
|
File.Delete(logFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteLog(logFilePath, "Upgrade Process Started: " + DateTime.UtcNow.ToString() + Environment.NewLine);
|
||||||
|
WriteLog(logFilePath, "ContentRootPath: " + contentrootfolder + Environment.NewLine);
|
||||||
|
WriteLog(logFilePath, "WebRootPath: " + webrootfolder + Environment.NewLine);
|
||||||
if (packagename != "" && File.Exists(Path.Combine(webrootfolder, "app_offline.bak")))
|
if (packagename != "" && File.Exists(Path.Combine(webrootfolder, "app_offline.bak")))
|
||||||
{
|
{
|
||||||
log += "Located Upgrade Package: " + packagename + Environment.NewLine;
|
WriteLog(logFilePath, "Located Upgrade Package: " + packagename + Environment.NewLine);
|
||||||
|
|
||||||
log += "Stopping Application Using: " + Path.Combine(contentrootfolder, "app_offline.htm") + Environment.NewLine;
|
WriteLog(logFilePath, "Stopping Application Using: " + Path.Combine(contentrootfolder, "app_offline.htm") + Environment.NewLine);
|
||||||
File.Copy(Path.Combine(webrootfolder, "app_offline.bak"), Path.Combine(contentrootfolder, "app_offline.htm"), true);
|
var offlineTemplate = File.ReadAllText(Path.Combine(webrootfolder, "app_offline.bak"));
|
||||||
|
var offlineFilePath = Path.Combine(contentrootfolder, "app_offline.htm");
|
||||||
|
|
||||||
// get list of files in package with local paths
|
// get list of files in package with local paths
|
||||||
log += "Retrieving List Of Files From Upgrade Package..." + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 5, "Retrieving List Of Files From Upgrade Package");
|
||||||
|
WriteLog(logFilePath, "Retrieving List Of Files From Upgrade Package..." + Environment.NewLine);
|
||||||
List<string> files = new List<string>();
|
List<string> files = new List<string>();
|
||||||
using (ZipArchive archive = ZipFile.OpenRead(packagename))
|
using (ZipArchive archive = ZipFile.OpenRead(packagename))
|
||||||
{
|
{
|
||||||
|
@ -59,15 +67,18 @@ namespace Oqtane.Updater
|
||||||
if (!string.IsNullOrEmpty(entry.Name))
|
if (!string.IsNullOrEmpty(entry.Name))
|
||||||
{
|
{
|
||||||
files.Add(Path.Combine(contentrootfolder, entry.FullName));
|
files.Add(Path.Combine(contentrootfolder, entry.FullName));
|
||||||
|
WriteLog(logFilePath, "Check File: " + entry.FullName + Environment.NewLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool success = true;
|
||||||
// ensure files are not locked
|
// ensure files are not locked
|
||||||
if (CanAccessFiles(files))
|
if (CanAccessFiles(files))
|
||||||
{
|
{
|
||||||
log += "Preparing Backup Folder: " + backupfolder + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 10, "Preparing Backup Folder");
|
||||||
bool success = true;
|
WriteLog(logFilePath, "Preparing Backup Folder: " + backupfolder + Environment.NewLine);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// clear out backup folder
|
// clear out backup folder
|
||||||
|
@ -79,14 +90,16 @@ namespace Oqtane.Updater
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log += "Error Creating Backup Folder: " + ex.Message + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 95, "Error Creating Backup Folder", "bg-danger");
|
||||||
|
WriteLog(logFilePath, "Error Creating Backup Folder: " + ex.Message + Environment.NewLine);
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// backup files
|
// backup files
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
log += "Backing Up Files..." + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 15, "Backing Up Files");
|
||||||
|
WriteLog(logFilePath, "Backing Up Files..." + Environment.NewLine);
|
||||||
foreach (string file in files)
|
foreach (string file in files)
|
||||||
{
|
{
|
||||||
string filename = Path.Combine(backupfolder, file.Replace(contentrootfolder + Path.DirectorySeparatorChar, ""));
|
string filename = Path.Combine(backupfolder, file.Replace(contentrootfolder + Path.DirectorySeparatorChar, ""));
|
||||||
|
@ -99,12 +112,15 @@ namespace Oqtane.Updater
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(filename));
|
Directory.CreateDirectory(Path.GetDirectoryName(filename));
|
||||||
}
|
}
|
||||||
File.Copy(file, filename);
|
File.Copy(file, filename);
|
||||||
|
WriteLog(logFilePath, "Copy File: " + filename + Environment.NewLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log += "Error Backing Up Files: " + ex.Message + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 95, "Error Backing Up Files", "bg-danger");
|
||||||
|
WriteLog(logFilePath, "Error Backing Up Files: " + ex.Message + Environment.NewLine);
|
||||||
success = false;
|
success = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +128,8 @@ namespace Oqtane.Updater
|
||||||
// extract files
|
// extract files
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
log += "Extracting Files From Upgrade Package..." + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 50, "Extracting Files From Upgrade Package");
|
||||||
|
WriteLog(logFilePath, "Extracting Files From Upgrade Package..." + Environment.NewLine);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ZipArchive archive = ZipFile.OpenRead(packagename))
|
using (ZipArchive archive = ZipFile.OpenRead(packagename))
|
||||||
|
@ -127,6 +144,7 @@ namespace Oqtane.Updater
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(filename));
|
Directory.CreateDirectory(Path.GetDirectoryName(filename));
|
||||||
}
|
}
|
||||||
entry.ExtractToFile(filename, true);
|
entry.ExtractToFile(filename, true);
|
||||||
|
WriteLog(logFilePath, "Exact File: " + filename + Environment.NewLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,12 +152,14 @@ namespace Oqtane.Updater
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
log += "Error Extracting Files From Upgrade Package: " + ex.Message + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 95, "Error Extracting Files From Upgrade Package", "bg-danger");
|
||||||
|
WriteLog(logFilePath, "Error Extracting Files From Upgrade Package: " + ex.Message + Environment.NewLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
log += "Removing Backup Folder..." + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 90, "Removing Backup Folder");
|
||||||
|
WriteLog(logFilePath, "Removing Backup Folder..." + Environment.NewLine);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// clean up backup
|
// clean up backup
|
||||||
|
@ -149,12 +169,14 @@ namespace Oqtane.Updater
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log += "Error Removing Backup Folder: " + ex.Message + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 95, "Error Extracting Files From Upgrade Package", "bg-warning");
|
||||||
|
WriteLog(logFilePath, "Error Removing Backup Folder: " + ex.Message + Environment.NewLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log += "Restoring Files From Backup Folder..." + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 50, "Upgrade Failed, Restoring Files From Backup Folder", "bg-warning");
|
||||||
|
WriteLog(logFilePath, "Restoring Files From Backup Folder..." + Environment.NewLine);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// restore on failure
|
// restore on failure
|
||||||
|
@ -165,6 +187,7 @@ namespace Oqtane.Updater
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
File.Copy(filename, file);
|
File.Copy(filename, file);
|
||||||
|
WriteLog(logFilePath, "Restore File: " + filename + Environment.NewLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// clean up backup
|
// clean up backup
|
||||||
|
@ -172,41 +195,38 @@ namespace Oqtane.Updater
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log += "Error Restoring Files From Backup Folder: " + ex.Message + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 95, "Error Restoring Files From Backup Folder", "bg-danger");
|
||||||
|
WriteLog(logFilePath, "Error Restoring Files From Backup Folder: " + ex.Message + Environment.NewLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log += "Upgrade Failed: Could Not Backup Files" + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 95, "Upgrade Failed: Could Not Backup Files", "bg-danger");
|
||||||
|
WriteLog(logFilePath, "Upgrade Failed: Could Not Backup Files" + Environment.NewLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log += "Upgrade Failed: Some Files Are Locked By The Hosting Environment" + Environment.NewLine;
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 95, "Upgrade Failed: Some Files Are Locked By The Hosting Environment", "bg-danger");
|
||||||
|
WriteLog(logFilePath, "Upgrade Failed: Some Files Are Locked By The Hosting Environment" + Environment.NewLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateOfflineContent(offlineFilePath, offlineTemplate, 100, "Upgrade Process Finished, Reloading", success ? "" : "bg-danger");
|
||||||
|
Thread.Sleep(3000); //wait for 3 seconds to complete the upgrade process.
|
||||||
// bring the app back online
|
// bring the app back online
|
||||||
if (File.Exists(Path.Combine(contentrootfolder, "app_offline.htm")))
|
if (File.Exists(Path.Combine(contentrootfolder, "app_offline.htm")))
|
||||||
{
|
{
|
||||||
log += "Restarting Application By Removing: " + Path.Combine(contentrootfolder, "app_offline.htm") + Environment.NewLine;
|
WriteLog(logFilePath, "Restarting Application By Removing: " + Path.Combine(contentrootfolder, "app_offline.htm") + Environment.NewLine);
|
||||||
File.Delete(Path.Combine(contentrootfolder, "app_offline.htm"));
|
File.Delete(Path.Combine(contentrootfolder, "app_offline.htm"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log += "Framework Upgrade Package Not Found Or " + Path.Combine(webrootfolder, "app_offline.bak") + " Does Not Exist" + Environment.NewLine;
|
WriteLog(logFilePath, "Framework Upgrade Package Not Found Or " + Path.Combine(webrootfolder, "app_offline.bak") + " Does Not Exist" + Environment.NewLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
log += "Upgrade Process Ended: " + DateTime.UtcNow.ToString() + Environment.NewLine;
|
WriteLog(logFilePath, "Upgrade Process Ended: " + DateTime.UtcNow.ToString() + Environment.NewLine);
|
||||||
|
|
||||||
// create upgrade log file
|
|
||||||
string logfile = Path.Combine(deployfolder, Path.GetFileNameWithoutExtension(packagename) + ".log");
|
|
||||||
if (File.Exists(logfile))
|
|
||||||
{
|
|
||||||
File.Delete(logfile);
|
|
||||||
}
|
|
||||||
File.WriteAllText(logfile, log);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -269,5 +289,19 @@ namespace Oqtane.Updater
|
||||||
}
|
}
|
||||||
return canAccess;
|
return canAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void UpdateOfflineContent(string filePath, string contentTemplate, int progress, string status, string progressClass = "")
|
||||||
|
{
|
||||||
|
var content = contentTemplate
|
||||||
|
.Replace("[PROGRESS]", progress.ToString())
|
||||||
|
.Replace("[PROGRESSCLASS]", progressClass)
|
||||||
|
.Replace("[STATUS]", status);
|
||||||
|
File.WriteAllText(filePath, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteLog(string logFilePath, string logContent)
|
||||||
|
{
|
||||||
|
File.AppendAllText(logFilePath, $"[{DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff")}] {logContent}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user