Fixed: Removal of previous service

Fixes #2040

(cherry picked from commit cd28af98eed831e00a400e66b652e6a8d6f9c442)
pull/2154/head
Mark McDowall 4 years ago committed by Qstick
parent 96c1d13790
commit 55372f554f

@ -62,9 +62,9 @@ Name: "{userstartup}\{#AppName}"; Filename: "{app}\Lidarr.exe"; WorkingDir: "{ap
Name: "{app}"; Type: filesandordirs
[Run]
Filename: "{app}\Lidarr.Console.exe"; StatusMsg: "Removing previous Windows Service"; Parameters: "/u"; Flags: runhidden waituntilterminated;
Filename: "{app}\Lidarr.Console.exe"; Description: "Enable Access from Other Devices"; StatusMsg: "Enabling Remote access"; Parameters: "/registerurl"; Flags: postinstall runascurrentuser runhidden waituntilterminated; Tasks: startupShortcut none;
Filename: "{app}\Lidarr.Console.exe"; StatusMsg: "Installing Windows Service"; Parameters: "/i"; Flags: runhidden waituntilterminated; Tasks: windowsService
Filename: "{app}\Lidarr.Console.exe"; StatusMsg: "Removing previous Windows Service"; Parameters: "/u /exitimmediately"; Flags: runhidden waituntilterminated;
Filename: "{app}\Lidarr.Console.exe"; Description: "Enable Access from Other Devices"; StatusMsg: "Enabling Remote access"; Parameters: "/registerurl /exitimmediately"; Flags: postinstall runascurrentuser runhidden waituntilterminated; Tasks: startupShortcut none;
Filename: "{app}\Lidarr.Console.exe"; StatusMsg: "Installing Windows Service"; Parameters: "/i /exitimmediately"; Flags: runhidden waituntilterminated; Tasks: windowsService
Filename: "{app}\Lidarr.exe"; Description: "Open Lidarr Web UI"; Flags: postinstall skipifsilent nowait; Tasks: windowsService;
Filename: "{app}\Lidarr.exe"; Description: "Start Lidarr"; Flags: postinstall skipifsilent nowait; Tasks: startupShortcut none;

@ -25,6 +25,7 @@ namespace NzbDrone.Common.EnvironmentInfo
public const string RESTART = "restart";
public const string REGISTER_URL = "registerurl";
public const string NO_SINGLE_INSTANCE_CHECK = "nosingleinstancecheck";
public const string EXIT_IMMEDIATELY = "exitimmediately";
public StartupContext(params string[] args)
{
@ -55,6 +56,7 @@ namespace NzbDrone.Common.EnvironmentInfo
public bool InstallService => Flags.Contains(INSTALL_SERVICE);
public bool UninstallService => Flags.Contains(UNINSTALL_SERVICE);
public bool RegisterUrl => Flags.Contains(REGISTER_URL);
public bool ExitImmediately => Flags.Contains(EXIT_IMMEDIATELY);
public string PreservedArguments
{

@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Net.Sockets;
using Microsoft.AspNetCore.Connections;
using NLog;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Exceptions;
@ -23,9 +25,11 @@ namespace NzbDrone.Console
public static void Main(string[] args)
{
StartupContext startupArgs = null;
try
{
var startupArgs = new StartupContext(args);
startupArgs = new StartupContext(args);
try
{
NzbDroneLogger.Register(startupArgs, false, true);
@ -43,37 +47,50 @@ namespace NzbDrone.Console
System.Console.WriteLine("");
System.Console.WriteLine("");
Logger.Fatal(ex, "EPIC FAIL!");
Exit(ExitCodes.NonRecoverableFailure);
Exit(ExitCodes.NonRecoverableFailure, startupArgs);
}
catch (SocketException ex)
{
System.Console.WriteLine("");
System.Console.WriteLine("");
Logger.Fatal(ex.Message + ". This can happen if another instance of Lidarr is already running another application is using the same port (default: 8686) or the user has insufficient permissions");
Exit(ExitCodes.RecoverableFailure);
Logger.Fatal(ex.Message + ". This can happen if another instance of Lidarr is already running another application is using the same port (default: 8989) or the user has insufficient permissions");
Exit(ExitCodes.RecoverableFailure, startupArgs);
}
catch (IOException ex)
{
if (ex.InnerException is AddressInUseException)
{
System.Console.WriteLine("");
System.Console.WriteLine("");
Logger.Fatal(ex.Message + " This can happen if another instance of Radarr is already running another application is using the same port (default: 7878) or the user has insufficient permissions");
Exit(ExitCodes.RecoverableFailure, startupArgs);
}
else
{
throw;
}
}
catch (RemoteAccessException ex)
{
System.Console.WriteLine("");
System.Console.WriteLine("");
Logger.Fatal(ex, "EPIC FAIL!");
Exit(ExitCodes.Normal);
Exit(ExitCodes.Normal, startupArgs);
}
catch (Exception ex)
{
System.Console.WriteLine("");
System.Console.WriteLine("");
Logger.Fatal(ex, "EPIC FAIL!");
System.Console.WriteLine("EPIC FAIL! " + ex.ToString());
Exit(ExitCodes.UnknownFailure);
Exit(ExitCodes.UnknownFailure, startupArgs);
}
Logger.Info("Exiting main.");
Exit(ExitCodes.Normal);
Exit(ExitCodes.Normal, startupArgs);
}
private static void Exit(ExitCodes exitCode)
private static void Exit(ExitCodes exitCode, StartupContext startupArgs)
{
LogManager.Shutdown();
@ -85,6 +102,13 @@ namespace NzbDrone.Console
if (exitCode == ExitCodes.NonRecoverableFailure)
{
if (startupArgs?.ExitImmediately == true)
{
System.Console.WriteLine("Non-recoverable failure, but set to exit immediately");
Environment.Exit((int)exitCode);
}
System.Console.WriteLine("Non-recoverable failure, waiting for user intervention...");
for (int i = 0; i < 3600; i++)
{

Loading…
Cancel
Save