@ -1,5 +1,7 @@
using System ;
using System ;
using System.IO ;
using System.Net.Sockets ;
using System.Net.Sockets ;
using Microsoft.AspNetCore.Connections ;
using NLog ;
using NLog ;
using NzbDrone.Common.EnvironmentInfo ;
using NzbDrone.Common.EnvironmentInfo ;
using NzbDrone.Common.Exceptions ;
using NzbDrone.Common.Exceptions ;
@ -23,9 +25,11 @@ namespace NzbDrone.Console
public static void Main ( string [ ] args )
public static void Main ( string [ ] args )
{
{
StartupContext startupArgs = null ;
try
try
{
{
var startupArgs = new StartupContext ( args ) ;
startupArgs = new StartupContext ( args ) ;
try
try
{
{
NzbDroneLogger . Register ( startupArgs , false , true ) ;
NzbDroneLogger . Register ( startupArgs , false , true ) ;
@ -43,37 +47,50 @@ namespace NzbDrone.Console
System . Console . WriteLine ( "" ) ;
System . Console . WriteLine ( "" ) ;
System . Console . WriteLine ( "" ) ;
System . Console . WriteLine ( "" ) ;
Logger . Fatal ( ex , "EPIC FAIL!" ) ;
Logger . Fatal ( ex , "EPIC FAIL!" ) ;
Exit ( ExitCodes . NonRecoverableFailure );
Exit ( ExitCodes . NonRecoverableFailure , startupArgs );
}
}
catch ( SocketException ex )
catch ( SocketException ex )
{
{
System . Console . WriteLine ( "" ) ;
System . Console . WriteLine ( "" ) ;
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" ) ;
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 ) ;
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 )
catch ( RemoteAccessException ex )
{
{
System . Console . WriteLine ( "" ) ;
System . Console . WriteLine ( "" ) ;
System . Console . WriteLine ( "" ) ;
System . Console . WriteLine ( "" ) ;
Logger . Fatal ( ex , "EPIC FAIL!" ) ;
Logger . Fatal ( ex , "EPIC FAIL!" ) ;
Exit ( ExitCodes . Normal ) ;
Exit ( ExitCodes . Normal , startupArgs );
}
}
catch ( Exception ex )
catch ( Exception ex )
{
{
System . Console . WriteLine ( "" ) ;
System . Console . WriteLine ( "" ) ;
System . Console . WriteLine ( "" ) ;
System . Console . WriteLine ( "" ) ;
Logger . Fatal ( ex , "EPIC FAIL!" ) ;
Logger . Fatal ( ex , "EPIC FAIL!" ) ;
System . Console . WriteLine ( "EPIC FAIL! " + ex . ToString ( ) ) ;
Exit ( ExitCodes . UnknownFailure , startupArgs ) ;
Exit ( ExitCodes . UnknownFailure ) ;
}
}
Logger . Info ( "Exiting main." ) ;
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 ( ) ;
LogManager . Shutdown ( ) ;
@ -85,6 +102,13 @@ namespace NzbDrone.Console
if ( exitCode = = ExitCodes . NonRecoverableFailure )
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..." ) ;
System . Console . WriteLine ( "Non-recoverable failure, waiting for user intervention..." ) ;
for ( int i = 0 ; i < 3600 ; i + + )
for ( int i = 0 ; i < 3600 ; i + + )
{
{