Merge branch 'develop' of https://github.com/tidusjar/ombi into develop

This commit is contained in:
TidusJar 2018-08-02 13:34:41 +01:00
commit e11b6d32a8
11 changed files with 385 additions and 67 deletions

View file

@ -72,7 +72,7 @@ namespace Ombi.Schedule.Jobs.Ombi
Logger.LogDebug(LoggingEvents.Updater, "Starting Update job");
var settings = await Settings.GetSettingsAsync();
if (!settings.AutoUpdateEnabled)
if (!settings.AutoUpdateEnabled && !settings.TestMode)
{
Logger.LogDebug(LoggingEvents.Updater, "Auto update is not enabled");
return;
@ -83,7 +83,7 @@ namespace Ombi.Schedule.Jobs.Ombi
var productVersion = AssemblyHelper.GetRuntimeVersion();
Logger.LogDebug(LoggingEvents.Updater, "Product Version {0}", productVersion);
var serverVersion = string.Empty;
try
{
var productArray = GetVersion();
@ -96,13 +96,17 @@ namespace Ombi.Schedule.Jobs.Ombi
Logger.LogDebug(LoggingEvents.Updater, "Branch {0}", branch);
Logger.LogDebug(LoggingEvents.Updater, "Looking for updates now");
//TODO this fails because the branch = featureupdater when it should be feature/updater
var updates = await Processor.Process(branch);
Logger.LogDebug(LoggingEvents.Updater, "Updates: {0}", updates);
var serverVersion = updates.UpdateVersionString;
serverVersion = updates.UpdateVersionString;
Logger.LogDebug(LoggingEvents.Updater, "Service Version {0}", updates.UpdateVersionString);
if (!serverVersion.Equals(version, StringComparison.CurrentCultureIgnoreCase))
if (!serverVersion.Equals(version, StringComparison.CurrentCultureIgnoreCase) || settings.TestMode)
{
// Let's download the correct zip
var desc = RuntimeInformation.OSDescription;
@ -135,7 +139,8 @@ namespace Ombi.Schedule.Jobs.Ombi
if (process == Architecture.Arm)
{
download = updates.Downloads.FirstOrDefault(x => x.Name.Contains("arm.", CompareOptions.IgnoreCase));
} else if (process == Architecture.Arm64)
}
else if (process == Architecture.Arm64)
{
download = updates.Downloads.FirstOrDefault(x => x.Name.Contains("arm64.", CompareOptions.IgnoreCase));
}
@ -206,33 +211,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())
//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.UserName = settings.Username;
proc.Start();
}
if (settings.Password.HasValue())
{
start.Password = settings.Password.ToSecureString();
}
var proc = new Process { StartInfo = start };
proc.Start();
Logger.LogDebug(LoggingEvents.Updater, "Bye bye");
}
}
@ -254,10 +261,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)
{

View file

@ -10,5 +10,6 @@
public string ScriptLocation { get; set; }
public string WindowsServiceName { get; set; }
public bool WindowsService { get; set; }
public bool TestMode { get; set; }
}
}

View file

@ -11,7 +11,7 @@ namespace Ombi.Updater
ProcessInfo GetCurrentProcess();
int GetCurrentProcessId();
ProcessInfo GetProcessById(int id);
void Kill(StartupOptions opts);
bool Kill(StartupOptions opts);
void KillAll(string processName);
void SetPriority(int processId, ProcessPriorityClass priority);
void WaitForExit(Process process);

View file

@ -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); // Since the updater is a folder deeper
_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);
}

View file

@ -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)

View file

@ -2,7 +2,7 @@
"profiles": {
"Ombi.Updater": {
"commandName": "Project",
"commandLineArgs": "--applicationPath \\\"C:\\\\Users\\\\Jamie\\\\Source\\\\Repos\\\\Ombi\\\\src\\\\Ombi\\\\bin\\\\Debug\\\\netcoreapp2.0\\\" --processname \\\"Ombi\\\" --startupArgs http://*:5000"
"commandLineArgs": "--applicationPath \"C:\\_git\\ombi\\src\\Ombi.Updater\\bin\\Debug\\netcoreapp2.0\" --processname \"Ombi\""
}
}
}

View file

@ -27,6 +27,7 @@ export interface IUpdateSettings extends ISettings {
windowsService: boolean;
windowsServiceName: string;
isWindows: boolean;
testMode: boolean;
}
export interface IEmbySettings extends ISettings {

View file

@ -5,8 +5,8 @@
<fieldset>
<legend>Update Settings</legend>
<div class="form-group" style="float: right">
<div *ngIf="updateAvailable">
<button (click)="update()" [disabled]="!enableUpdateButton" class="btn btn-success-outline">Update</button>
<div *ngIf="updateAvailable || form.controls['testMode'].value">
<button (click)="update()" [disabled]="!enableUpdateButton || !form.controls['testMode'].value" class="btn btn-success-outline">Update</button>
</div>
<div *ngIf="!updateAvailable">
<button (click)="checkForUpdate()" class="btn btn-primary-outline">Check For Update</button>
@ -19,8 +19,13 @@
<input type="checkbox" id="autoUpdateEnabled" formControlName="autoUpdateEnabled">
<label for="autoUpdateEnabled">Enable Automatic Update</label>
</div>
</div>
</div>
<!-- <div class="form-group">
<div class="checkbox">
<input type="checkbox" id="testMode" formControlName="testMode">
<label for="testMode">Test Mode</label>
</div>
</div> -->
<div class="form-group" *ngIf="isWindows">
<div class="checkbox">
<input type="checkbox" id="windowsService" formControlName="windowsService">

View file

@ -35,6 +35,7 @@ export class UpdateComponent implements OnInit {
scriptLocation: [x.scriptLocation],
windowsService: [x.windowsService],
windowsServiceName: [x.windowsServiceName],
testMode: [x.testMode],
});
this.isWindows = x.isWindows;
this.enableUpdateButton = x.autoUpdateEnabled;
@ -62,7 +63,7 @@ export class UpdateComponent implements OnInit {
this.notificationService.error("Please check your entered values");
return;
}
this.enableUpdateButton = form.value.autoUpdateEnabled;
this.enableUpdateButton = form.value.autoUpdateEnabled || form.value.testMode;
this.settingsService.saveUpdateSettings(form.value)
.subscribe(x => {
if (x) {