!wip try a different way to update

pull/2420/head
Jamie Rees 7 years ago
parent 368d644741
commit 760987579a

@ -173,11 +173,11 @@ Task("Package")
Task("Publish") Task("Publish")
.IsDependentOn("PrePublish") .IsDependentOn("PrePublish")
.IsDependentOn("Publish-Windows") //.IsDependentOn("Publish-Windows")
.IsDependentOn("Publish-Windows-32bit") .IsDependentOn("Publish-Windows-32bit")
.IsDependentOn("Publish-OSX") //.IsDependentOn("Publish-OSX")
.IsDependentOn("Publish-Linux") //.IsDependentOn("Publish-Linux")
.IsDependentOn("Publish-Linux-ARM") //.IsDependentOn("Publish-Linux-ARM")
//.IsDependentOn("Publish-Linux-ARM-64Bit") //.IsDependentOn("Publish-Linux-ARM-64Bit")
.IsDependentOn("Package"); .IsDependentOn("Package");
@ -189,6 +189,8 @@ Task("Publish-Windows")
DotNetCorePublish("./src/Ombi/Ombi.csproj", publishSettings); DotNetCorePublish("./src/Ombi/Ombi.csproj", publishSettings);
CopyFile(buildDir + "/"+frameworkVer+"/win10-x64/Swagger.xml", buildDir + "/"+frameworkVer+"/win10-x64/published/Swagger.xml"); 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); DotNetCorePublish("./src/Ombi.Updater/Ombi.Updater.csproj", publishSettings);
}); });

@ -206,33 +206,35 @@ namespace Ombi.Schedule.Jobs.Ombi
updaterExtension = ".exe"; updaterExtension = ".exe";
} }
var updaterFile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), 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 // Make sure the file is an executable
ExecLinuxCommand($"chmod +x {updaterFile}"); //ExecLinuxCommand($"chmod +x {updaterFile}");
// There must be an update // There must be an update
var start = new ProcessStartInfo var start = new ProcessStartInfo
{ {
UseShellExecute = true, UseShellExecute = false,
CreateNoWindow = false, // Ignored if UseShellExecute is set to true CreateNoWindow = true, // Ignored if UseShellExecute is set to true
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"),
}; };
if (settings.Username.HasValue()) //if (settings.Username.HasValue())
{ //{
start.UserName = settings.Username; // start.UserName = settings.Username;
} //}
if (settings.Password.HasValue()) //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"); Logger.LogDebug(LoggingEvents.Updater, "Bye bye");
} }
} }
@ -254,10 +256,10 @@ namespace Ombi.Schedule.Jobs.Ombi
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.Append($"--applicationPath \"{currentLocation}\" --processname \"{processName}\" "); sb.Append($"--applicationPath \"{currentLocation}\" --processname \"{processName}\" ");
if (settings.WindowsService) //if (settings.WindowsService)
{ //{
sb.Append($"--windowsServiceName \"{settings.WindowsServiceName}\" "); // sb.Append($"--windowsServiceName \"{settings.WindowsServiceName}\" ");
} //}
var sb2 = new StringBuilder(); var sb2 = new StringBuilder();
if (url?.Value.HasValue() ?? false) if (url?.Value.HasValue() ?? false)
{ {

@ -22,29 +22,23 @@ namespace Ombi.Updater
{ {
// Kill Ombi Process // Kill Ombi Process
var p = new ProcessProvider(); var p = new ProcessProvider();
bool killed = false;
try try
{ {
p.Kill(opt); killed = p.Kill(opt);
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine(e); Console.WriteLine(e);
} }
// Make sure the process has been killed if (!killed)
while (p.FindProcessByName(opt.ProcessName).Any())
{ {
Thread.Sleep(500);
_log.LogDebug("Found another process called {0}, KILLING!", opt.ProcessName); _log.LogDebug("Couldn't kill the ombi process");
var proc = p.FindProcessByName(opt.ProcessName).FirstOrDefault(); return;
if (proc != null)
{
_log.LogDebug($"[{proc.Id}] - {proc.Name} - Path: {proc.StartPath}");
opt.OmbiProcessId = proc.Id;
p.Kill(opt);
}
} }
_log.LogDebug("Starting to move the files"); _log.LogDebug("Starting to move the files");
@ -111,21 +105,23 @@ namespace Ombi.Updater
var location = System.Reflection.Assembly.GetEntryAssembly().Location; var location = System.Reflection.Assembly.GetEntryAssembly().Location;
location = Path.GetDirectoryName(location); location = Path.GetDirectoryName(location);
_log.LogDebug("We are currently in dir {0}", 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); _log.LogDebug("Ombi is installed at {0}", options.ApplicationPath);
//Now Create all of the directories //Now Create all of the directories
foreach (string dirPath in Directory.GetDirectories(location, "*", foreach (string dirPath in Directory.GetDirectories(updatedLocation, "*",
SearchOption.AllDirectories)) SearchOption.AllDirectories))
{ {
var newDir = dirPath.Replace(location, options.ApplicationPath); var newDir = dirPath.Replace(updatedLocation, options.ApplicationPath);
Directory.CreateDirectory(newDir); Directory.CreateDirectory(newDir);
_log.LogDebug("Created dir {0}", newDir); _log.LogDebug("Created dir {0}", newDir);
} }
//Copy all the files & Replaces any files with the same name //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)) SearchOption.AllDirectories))
{ {
var newFile = currentPath.Replace(location, options.ApplicationPath); var newFile = currentPath.Replace(updatedLocation, options.ApplicationPath);
File.Copy(currentPath, newFile, true); File.Copy(currentPath, newFile, true);
_log.LogDebug("Replaced file {0}", newFile); _log.LogDebug("Replaced file {0}", newFile);
} }

@ -73,33 +73,32 @@ namespace Ombi.Updater
process.PriorityClass = priority; process.PriorityClass = priority;
} }
public void Kill(StartupOptions opts) public bool Kill(StartupOptions opts)
{ {
if (opts.IsWindowsService) //if (opts.IsWindowsService)
{ //{
Console.WriteLine("Stopping Service {0}", opts.WindowsServiceName); // Console.WriteLine("Stopping Service {0}", opts.WindowsServiceName);
var process = new Process(); // var process = new Process();
var startInfo = // var startInfo =
new ProcessStartInfo // new ProcessStartInfo
{ // {
WindowStyle = ProcessWindowStyle.Hidden, // WindowStyle = ProcessWindowStyle.Hidden,
FileName = "cmd.exe", // FileName = "cmd.exe",
Arguments = $"/C net stop \"{opts.WindowsServiceName}\"" // Arguments = $"/C net stop \"{opts.WindowsServiceName}\""
}; // };
process.StartInfo = startInfo; // process.StartInfo = startInfo;
process.Start(); // process.Start();
} //}
else //else
{ //{
var process = Process.GetProcesses().FirstOrDefault(p => p.ProcessName == opts.ProcessName); var process = Process.GetProcesses().FirstOrDefault(p => p.ProcessName == opts.ProcessName);
if (process == null) if (process == null)
{ {
Console.WriteLine("Cannot find process with name: {0}", opts.ProcessName); Console.WriteLine("Cannot find process with name: {0}", opts.ProcessName);
return; return false;
} }
process.Refresh();
if (process.Id > 0) if (process.Id > 0)
{ {
@ -108,8 +107,12 @@ namespace Ombi.Updater
Console.WriteLine("[{0}]: Waiting for exit", process.Id); Console.WriteLine("[{0}]: Waiting for exit", process.Id);
process.WaitForExit(); process.WaitForExit();
Console.WriteLine("[{0}]: Process terminated successfully", process.Id); Console.WriteLine("[{0}]: Process terminated successfully", process.Id);
return true;
} }
}
return false;
//}
} }
public void KillAll(string processName) public void KillAll(string processName)

Loading…
Cancel
Save