mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
Some work on the auto updater #1460
This commit is contained in:
parent
96697000b1
commit
03f7184118
5 changed files with 104 additions and 75 deletions
|
@ -69,40 +69,38 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
public async Task Update(PerformContext c)
|
public async Task Update(PerformContext c)
|
||||||
{
|
{
|
||||||
Ctx = c;
|
Ctx = c;
|
||||||
Logger.LogInformation("Starting the updater");
|
Logger.LogDebug(LoggingEvents.Updater, "Starting Update job");
|
||||||
|
|
||||||
var settings = await Settings.GetSettingsAsync();
|
var settings = await Settings.GetSettingsAsync();
|
||||||
if (!settings.AutoUpdateEnabled)
|
if (!settings.AutoUpdateEnabled)
|
||||||
{
|
{
|
||||||
Logger.LogInformation("Auto update is not enabled");
|
Logger.LogDebug(LoggingEvents.Updater, "Auto update is not enabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
var currentLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
Logger.LogInformation("Path: {0}", currentLocation);
|
Logger.LogDebug(LoggingEvents.Updater, "Path: {0}", currentLocation);
|
||||||
|
|
||||||
var productVersion = AssemblyHelper.GetRuntimeVersion();
|
var productVersion = AssemblyHelper.GetRuntimeVersion();
|
||||||
Logger.LogInformation(LoggingEvents.Updater, "Product Version {0}", productVersion);
|
Logger.LogDebug(LoggingEvents.Updater, "Product Version {0}", productVersion);
|
||||||
Logger.LogInformation("Product Version {0}", productVersion);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var productArray = GetVersion();
|
var productArray = GetVersion();
|
||||||
var version = productArray[0];
|
var version = productArray[0];
|
||||||
Logger.LogInformation("Version {0}", version);
|
Logger.LogDebug(LoggingEvents.Updater, "Version {0}", version);
|
||||||
var branch = productArray[1];
|
var branch = productArray[1];
|
||||||
Logger.LogInformation("Branch Version {0}", branch);
|
Logger.LogDebug(LoggingEvents.Updater, "Branch Version {0}", branch);
|
||||||
|
|
||||||
Logger.LogInformation(LoggingEvents.Updater, "Version {0}", version);
|
Logger.LogDebug(LoggingEvents.Updater, "Version {0}", version);
|
||||||
Logger.LogInformation(LoggingEvents.Updater, "Branch {0}", branch);
|
Logger.LogDebug(LoggingEvents.Updater, "Branch {0}", branch);
|
||||||
|
|
||||||
Logger.LogInformation("Looking for updates now");
|
Logger.LogDebug(LoggingEvents.Updater, "Looking for updates now");
|
||||||
var updates = await Processor.Process(branch);
|
var updates = await Processor.Process(branch);
|
||||||
Logger.LogInformation("Updates: {0}", updates);
|
Logger.LogDebug(LoggingEvents.Updater, "Updates: {0}", updates);
|
||||||
var serverVersion = updates.UpdateVersionString;
|
var serverVersion = updates.UpdateVersionString;
|
||||||
|
|
||||||
Logger.LogInformation(LoggingEvents.Updater, "Service Version {0}", updates.UpdateVersionString);
|
Logger.LogDebug(LoggingEvents.Updater, "Service Version {0}", updates.UpdateVersionString);
|
||||||
Logger.LogInformation("Service Version {0}", updates.UpdateVersionString);
|
|
||||||
|
|
||||||
if (!serverVersion.Equals(version, StringComparison.CurrentCultureIgnoreCase))
|
if (!serverVersion.Equals(version, StringComparison.CurrentCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
|
@ -110,38 +108,37 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
var desc = RuntimeInformation.OSDescription;
|
var desc = RuntimeInformation.OSDescription;
|
||||||
var proce = RuntimeInformation.ProcessArchitecture;
|
var proce = RuntimeInformation.ProcessArchitecture;
|
||||||
|
|
||||||
Logger.LogInformation(LoggingEvents.Updater, "OS Information: {0} {1}", desc, proce);
|
Logger.LogDebug(LoggingEvents.Updater, "OS Information: {0} {1}", desc, proce);
|
||||||
Logger.LogInformation("OS Information: {0} {1}", desc, proce);
|
|
||||||
Downloads download;
|
Downloads download;
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
Logger.LogInformation(LoggingEvents.Updater, "We are Windows");
|
Logger.LogDebug(LoggingEvents.Updater, "We are Windows");
|
||||||
download = updates.Downloads.FirstOrDefault(x => x.Name.Contains("windows.zip", CompareOptions.IgnoreCase));
|
download = updates.Downloads.FirstOrDefault(x => x.Name.Contains("windows.zip", CompareOptions.IgnoreCase));
|
||||||
}
|
}
|
||||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
{
|
{
|
||||||
Logger.LogInformation(LoggingEvents.Updater, "We are OSX");
|
Logger.LogDebug(LoggingEvents.Updater, "We are OSX");
|
||||||
download = updates.Downloads.FirstOrDefault(x => x.Name.Contains("osx", CompareOptions.IgnoreCase));
|
download = updates.Downloads.FirstOrDefault(x => x.Name.Contains("osx", CompareOptions.IgnoreCase));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.LogInformation(LoggingEvents.Updater, "We are linux");
|
Logger.LogDebug(LoggingEvents.Updater, "We are linux");
|
||||||
download = updates.Downloads.FirstOrDefault(x => x.Name.Contains("linux", CompareOptions.IgnoreCase));
|
download = updates.Downloads.FirstOrDefault(x => x.Name.Contains("linux", CompareOptions.IgnoreCase));
|
||||||
}
|
}
|
||||||
if (download == null)
|
if (download == null)
|
||||||
{
|
{
|
||||||
Logger.LogInformation("There were no downloads");
|
Logger.LogDebug(LoggingEvents.Updater, "There were no downloads");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.LogInformation("Found the download! {0}", download.Name);
|
Logger.LogDebug(LoggingEvents.Updater, "Found the download! {0}", download.Name);
|
||||||
Logger.LogInformation("URL {0}", download.Url);
|
Logger.LogDebug(LoggingEvents.Updater, "URL {0}", download.Url);
|
||||||
|
|
||||||
Logger.LogInformation("Clearing out Temp Path");
|
Logger.LogDebug(LoggingEvents.Updater, "Clearing out Temp Path");
|
||||||
var tempPath = Path.Combine(currentLocation, "TempUpdate");
|
var tempPath = Path.Combine(currentLocation, "TempUpdate");
|
||||||
if (Directory.Exists(tempPath))
|
if (Directory.Exists(tempPath))
|
||||||
{
|
{
|
||||||
Directory.Delete(tempPath, true);
|
DeleteDirectory(tempPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temp Path
|
// Temp Path
|
||||||
|
@ -155,10 +152,10 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download it
|
// Download it
|
||||||
Logger.LogInformation(LoggingEvents.Updater, "Downloading the file {0} from {1}", download.Name, download.Url);
|
Logger.LogDebug(LoggingEvents.Updater, "Downloading the file {0} from {1}", download.Name, download.Url);
|
||||||
var extension = download.Name.Split('.').Last();
|
var extension = download.Name.Split('.').Last();
|
||||||
var zipDir = Path.Combine(currentLocation, $"Ombi.{extension}");
|
var zipDir = Path.Combine(currentLocation, $"Ombi.{extension}");
|
||||||
Logger.LogInformation("Zip Dir: {0}", zipDir);
|
Logger.LogDebug(LoggingEvents.Updater, "Zip Dir: {0}", zipDir);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (File.Exists(zipDir))
|
if (File.Exists(zipDir))
|
||||||
|
@ -166,24 +163,24 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
File.Delete(zipDir);
|
File.Delete(zipDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.LogInformation("Starting Download");
|
Logger.LogDebug(LoggingEvents.Updater, "Starting Download");
|
||||||
await DownloadAsync(download.Url, zipDir, c);
|
await DownloadAsync(download.Url, zipDir, c);
|
||||||
Logger.LogInformation("Finished Download");
|
Logger.LogDebug(LoggingEvents.Updater, "Finished Download");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.LogInformation("Error when downloading");
|
Logger.LogDebug(LoggingEvents.Updater, "Error when downloading");
|
||||||
Logger.LogInformation(e.Message);
|
Logger.LogDebug(LoggingEvents.Updater, e.Message);
|
||||||
Logger.LogError(LoggingEvents.Updater, e, "Error when downloading the zip");
|
Logger.LogError(LoggingEvents.Updater, e, "Error when downloading the zip");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract it
|
// Extract it
|
||||||
Logger.LogInformation("Extracting ZIP");
|
Logger.LogDebug(LoggingEvents.Updater, "Extracting ZIP");
|
||||||
Extract(zipDir, tempPath);
|
Extract(zipDir, tempPath);
|
||||||
|
|
||||||
Logger.LogInformation("Finished Extracting files");
|
Logger.LogDebug(LoggingEvents.Updater, "Finished Extracting files");
|
||||||
Logger.LogInformation("Starting the Ombi.Updater process");
|
Logger.LogDebug(LoggingEvents.Updater, "Starting the Ombi.Updater process");
|
||||||
var updaterExtension = string.Empty;
|
var updaterExtension = string.Empty;
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
|
@ -196,7 +193,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
var start = new ProcessStartInfo
|
var start = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = false,
|
||||||
FileName = updaterFile,
|
FileName = updaterFile,
|
||||||
Arguments = GetArgs(settings),
|
Arguments = GetArgs(settings),
|
||||||
WorkingDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "TempUpdate"),
|
WorkingDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "TempUpdate"),
|
||||||
|
@ -209,11 +206,12 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
{
|
{
|
||||||
start.Password = settings.Password.ToSecureString();
|
start.Password = settings.Password.ToSecureString();
|
||||||
}
|
}
|
||||||
using (var proc = new Process { StartInfo = start })
|
var proc = new Process {StartInfo = start};
|
||||||
{
|
|
||||||
|
|
||||||
proc.Start();
|
proc.Start();
|
||||||
}
|
|
||||||
Logger.LogInformation("Bye bye");
|
Logger.LogDebug(LoggingEvents.Updater, "Bye bye");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -276,7 +274,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
|
|
||||||
_processProvider.Start(scriptToRun, downloadUrl + " " + GetArgs(settings));
|
_processProvider.Start(scriptToRun, downloadUrl + " " + GetArgs(settings));
|
||||||
|
|
||||||
Logger.LogInformation("Script started");
|
Logger.LogDebug(LoggingEvents.Updater, "Script started");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Extract(string zipDir, string tempPath)
|
private void Extract(string zipDir, string tempPath)
|
||||||
|
@ -311,7 +309,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
|
|
||||||
public async Task DownloadAsync(string requestUri, string filename, PerformContext ctx)
|
public async Task DownloadAsync(string requestUri, string filename, PerformContext ctx)
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Starting the DownloadAsync");
|
Logger.LogDebug(LoggingEvents.Updater, "Starting the DownloadAsync");
|
||||||
using (var client = new WebClient())
|
using (var client = new WebClient())
|
||||||
{
|
{
|
||||||
await client.DownloadFileTaskAsync(requestUri, filename);
|
await client.DownloadFileTaskAsync(requestUri, filename);
|
||||||
|
@ -337,5 +335,30 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Depth-first recursive delete, with handling for descendant
|
||||||
|
/// directories open in Windows Explorer.
|
||||||
|
/// </summary>
|
||||||
|
public static void DeleteDirectory(string path)
|
||||||
|
{
|
||||||
|
foreach (string directory in Directory.GetDirectories(path))
|
||||||
|
{
|
||||||
|
DeleteDirectory(directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(path, true);
|
||||||
|
}
|
||||||
|
catch (IOException)
|
||||||
|
{
|
||||||
|
Directory.Delete(path, true);
|
||||||
|
}
|
||||||
|
catch (UnauthorizedAccessException)
|
||||||
|
{
|
||||||
|
Directory.Delete(path, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,7 +21,16 @@ namespace Ombi.Updater
|
||||||
{
|
{
|
||||||
// Kill Ombi Process
|
// Kill Ombi Process
|
||||||
var p = new ProcessProvider();
|
var p = new ProcessProvider();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
p.Kill(opt);
|
p.Kill(opt);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure the process has been killed
|
// Make sure the process has been killed
|
||||||
while (p.FindProcessByName(opt.ProcessName).Any())
|
while (p.FindProcessByName(opt.ProcessName).Any())
|
||||||
|
|
|
@ -91,22 +91,18 @@ namespace Ombi.Updater
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var process = Process.GetProcesses().FirstOrDefault(p => p.Id == opts.OmbiProcessId);
|
var process = Process.GetProcesses().FirstOrDefault(p => p.ProcessName == opts.ProcessName);
|
||||||
|
|
||||||
if (process == null)
|
if (process == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Cannot find process with id: {0}", opts.OmbiProcessId);
|
Console.WriteLine("Cannot find process with name: {0}", opts.ProcessName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
process.Refresh();
|
process.Refresh();
|
||||||
|
|
||||||
if (process.Id != Process.GetCurrentProcess().Id && process.HasExited)
|
if (process.Id > 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Process has already exited");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("[{0}]: Killing process", process.Id);
|
Console.WriteLine("[{0}]: Killing process", process.Id);
|
||||||
process.Kill();
|
process.Kill();
|
||||||
Console.WriteLine("[{0}]: Waiting for exit", process.Id);
|
Console.WriteLine("[{0}]: Waiting for exit", process.Id);
|
||||||
|
@ -114,6 +110,7 @@ namespace Ombi.Updater
|
||||||
Console.WriteLine("[{0}]: Process terminated successfully", process.Id);
|
Console.WriteLine("[{0}]: Process terminated successfully", process.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void KillAll(string processName)
|
public void KillAll(string processName)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"Ombi.Updater": {
|
"Ombi.Updater": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "--applicationPath C:\\\\Users\\\\Jamie.Rees\\\\Source\\\\Repos\\\\test\\\\Ombi\\\\src\\\\Ombi\\\\bin\\\\Debug\\\\netcoreapp2.0 --processname Ombi --windowsServiceName \"World Wide Publishing Service\" --startupArgs http://*:5000"
|
"commandLineArgs": "--applicationPath \\\"C:\\\\Users\\\\Jamie\\\\Source\\\\Repos\\\\Ombi\\\\src\\\\Ombi\\\\bin\\\\Debug\\\\netcoreapp2.0\\\" --processname \\\"Ombi\\\" --startupArgs http://*:5000"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,8 +2,8 @@
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"IncludeScopes": false,
|
"IncludeScopes": false,
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Debug",
|
||||||
"System": "Information",
|
"System": "Debug",
|
||||||
"Microsoft": "None"
|
"Microsoft": "None"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue