diff --git a/build.cake b/build.cake index a497c5f77..7837cdc44 100644 --- a/build.cake +++ b/build.cake @@ -173,11 +173,11 @@ Task("Package") Task("Publish") .IsDependentOn("PrePublish") - .IsDependentOn("Publish-Windows") + //.IsDependentOn("Publish-Windows") .IsDependentOn("Publish-Windows-32bit") - .IsDependentOn("Publish-OSX") - .IsDependentOn("Publish-Linux") - .IsDependentOn("Publish-Linux-ARM") + //.IsDependentOn("Publish-OSX") + //.IsDependentOn("Publish-Linux") + //.IsDependentOn("Publish-Linux-ARM") //.IsDependentOn("Publish-Linux-ARM-64Bit") .IsDependentOn("Package"); @@ -189,6 +189,8 @@ Task("Publish-Windows") DotNetCorePublish("./src/Ombi/Ombi.csproj", publishSettings); CopyFile(buildDir + "/"+frameworkVer+"/win10-x64/Swagger.xml", buildDir + "/"+frameworkVer+"/win10-x64/published/Swagger.xml"); + + publishSettings.OutputDirectory = Directory(buildDir) + Directory(frameworkVer +"/win10-x64/published/updater"); DotNetCorePublish("./src/Ombi.Updater/Ombi.Updater.csproj", publishSettings); }); diff --git a/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs b/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs index da3b3305c..d5e2881e7 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs @@ -206,33 +206,35 @@ namespace Ombi.Schedule.Jobs.Ombi updaterExtension = ".exe"; } var updaterFile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), - "TempUpdate", $"Ombi.Updater{updaterExtension}"); + "TempUpdate", "Updater", $"Ombi.Updater{updaterExtension}"); // Make sure the file is an executable - ExecLinuxCommand($"chmod +x {updaterFile}"); + //ExecLinuxCommand($"chmod +x {updaterFile}"); + // There must be an update var start = new ProcessStartInfo { - UseShellExecute = true, - CreateNoWindow = false, // Ignored if UseShellExecute is set to true + UseShellExecute = false, + CreateNoWindow = true, // Ignored if UseShellExecute is set to true FileName = updaterFile, Arguments = GetArgs(settings), WorkingDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "TempUpdate"), }; - if (settings.Username.HasValue()) - { - start.UserName = settings.Username; - } - if (settings.Password.HasValue()) + //if (settings.Username.HasValue()) + //{ + // start.UserName = settings.Username; + //} + //if (settings.Password.HasValue()) + //{ + // start.Password = settings.Password.ToSecureString(); + //} + using (var proc = new Process { StartInfo = start }) { - start.Password = settings.Password.ToSecureString(); + proc.Start(); } - var proc = new Process { StartInfo = start }; - proc.Start(); - Logger.LogDebug(LoggingEvents.Updater, "Bye bye"); } } @@ -254,10 +256,10 @@ namespace Ombi.Schedule.Jobs.Ombi var sb = new StringBuilder(); sb.Append($"--applicationPath \"{currentLocation}\" --processname \"{processName}\" "); - if (settings.WindowsService) - { - sb.Append($"--windowsServiceName \"{settings.WindowsServiceName}\" "); - } + //if (settings.WindowsService) + //{ + // sb.Append($"--windowsServiceName \"{settings.WindowsServiceName}\" "); + //} var sb2 = new StringBuilder(); if (url?.Value.HasValue() ?? false) { diff --git a/src/Ombi.Updater/Installer.cs b/src/Ombi.Updater/Installer.cs index 4827d45f9..ec72945d9 100644 --- a/src/Ombi.Updater/Installer.cs +++ b/src/Ombi.Updater/Installer.cs @@ -22,29 +22,23 @@ namespace Ombi.Updater { // Kill Ombi Process var p = new ProcessProvider(); + bool killed = false; try { - p.Kill(opt); + killed = p.Kill(opt); } catch (Exception e) { Console.WriteLine(e); } - // Make sure the process has been killed - while (p.FindProcessByName(opt.ProcessName).Any()) + if (!killed) { - Thread.Sleep(500); - _log.LogDebug("Found another process called {0}, KILLING!", opt.ProcessName); - var proc = p.FindProcessByName(opt.ProcessName).FirstOrDefault(); - if (proc != null) - { - _log.LogDebug($"[{proc.Id}] - {proc.Name} - Path: {proc.StartPath}"); - opt.OmbiProcessId = proc.Id; - p.Kill(opt); - } + + _log.LogDebug("Couldn't kill the ombi process"); + return; } _log.LogDebug("Starting to move the files"); @@ -111,21 +105,23 @@ namespace Ombi.Updater var location = System.Reflection.Assembly.GetEntryAssembly().Location; location = Path.GetDirectoryName(location); _log.LogDebug("We are currently in dir {0}", location); + var updatedLocation = Directory.GetParent(location).FullName; + _log.LogDebug("The files are in {0}", updatedLocation); _log.LogDebug("Ombi is installed at {0}", options.ApplicationPath); //Now Create all of the directories - foreach (string dirPath in Directory.GetDirectories(location, "*", + foreach (string dirPath in Directory.GetDirectories(updatedLocation, "*", SearchOption.AllDirectories)) { - var newDir = dirPath.Replace(location, options.ApplicationPath); + var newDir = dirPath.Replace(updatedLocation, options.ApplicationPath); Directory.CreateDirectory(newDir); _log.LogDebug("Created dir {0}", newDir); } //Copy all the files & Replaces any files with the same name - foreach (string currentPath in Directory.GetFiles(location, "*.*", + foreach (string currentPath in Directory.GetFiles(updatedLocation, "*.*", SearchOption.AllDirectories)) { - var newFile = currentPath.Replace(location, options.ApplicationPath); + var newFile = currentPath.Replace(updatedLocation, options.ApplicationPath); File.Copy(currentPath, newFile, true); _log.LogDebug("Replaced file {0}", newFile); } diff --git a/src/Ombi.Updater/ProcessProvider.cs b/src/Ombi.Updater/ProcessProvider.cs index 3a3f36355..f3324fc47 100644 --- a/src/Ombi.Updater/ProcessProvider.cs +++ b/src/Ombi.Updater/ProcessProvider.cs @@ -73,33 +73,32 @@ namespace Ombi.Updater process.PriorityClass = priority; } - public void Kill(StartupOptions opts) + public bool Kill(StartupOptions opts) { - if (opts.IsWindowsService) - { - Console.WriteLine("Stopping Service {0}", opts.WindowsServiceName); - var process = new Process(); - var startInfo = - new ProcessStartInfo - { - WindowStyle = ProcessWindowStyle.Hidden, - FileName = "cmd.exe", - Arguments = $"/C net stop \"{opts.WindowsServiceName}\"" - }; - process.StartInfo = startInfo; - process.Start(); - } - else - { + //if (opts.IsWindowsService) + //{ + // Console.WriteLine("Stopping Service {0}", opts.WindowsServiceName); + // var process = new Process(); + // var startInfo = + // new ProcessStartInfo + // { + // WindowStyle = ProcessWindowStyle.Hidden, + // FileName = "cmd.exe", + // Arguments = $"/C net stop \"{opts.WindowsServiceName}\"" + // }; + // process.StartInfo = startInfo; + // process.Start(); + //} + //else + //{ var process = Process.GetProcesses().FirstOrDefault(p => p.ProcessName == opts.ProcessName); if (process == null) { Console.WriteLine("Cannot find process with name: {0}", opts.ProcessName); - return; + return false; } - - process.Refresh(); + if (process.Id > 0) { @@ -108,8 +107,12 @@ namespace Ombi.Updater Console.WriteLine("[{0}]: Waiting for exit", process.Id); process.WaitForExit(); Console.WriteLine("[{0}]: Process terminated successfully", process.Id); + + return true; } - } + + return false; + //} } public void KillAll(string processName)