@ -1,7 +1,7 @@
using System ;
using System.IO ;
using System.Net.Sockets ;
using Microsoft.AspNetCore.Hosting ;
using Microsoft.Extensions.Hosting ;
using Microsoft.AspNetCore.Connections ;
using NLog ;
using NzbDrone.Common.EnvironmentInfo ;
using NzbDrone.Common.Exceptions ;
@ -25,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 ) ;
@ -45,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 Readarr is already running another application is using the same port (default: 8787) 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 )
{
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 ( ) ;
@ -87,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 + + )
{