improve Address already in use error handling

This commit is contained in:
kaso17 2017-01-26 13:54:52 +01:00
parent 0a6d2b30b5
commit 40f930591a
1 changed files with 15 additions and 1 deletions

View File

@ -17,6 +17,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
@ -187,7 +188,20 @@ namespace Jackett.Services
var startOptions = new StartOptions();
config.GetListenAddresses().ToList().ForEach(u => startOptions.Urls.Add(u));
Startup.BasePath = BasePath();
_server = WebApp.Start<Startup>(startOptions);
try
{
_server = WebApp.Start<Startup>(startOptions);
}
catch (TargetInvocationException e)
{
var inner = e.InnerException;
if (inner is SocketException && ((SocketException)inner).SocketErrorCode == SocketError.AddressAlreadyInUse)
{
logger.Error("Address already in use: Most likely Jackett is already running");
Environment.Exit(1);
}
throw e;
}
logger.Debug("Web server started");
updater.StartUpdateChecker();
}