diff --git a/NzbDrone.Host/NzbDrone.Host.csproj b/NzbDrone.Host/NzbDrone.Host.csproj index 49c4850bd..ad7214da7 100644 --- a/NzbDrone.Host/NzbDrone.Host.csproj +++ b/NzbDrone.Host/NzbDrone.Host.csproj @@ -125,6 +125,7 @@ + diff --git a/NzbDrone.Host/Owin/OwinHostController.cs b/NzbDrone.Host/Owin/OwinHostController.cs index 9968b22bb..8eabe82b5 100644 --- a/NzbDrone.Host/Owin/OwinHostController.cs +++ b/NzbDrone.Host/Owin/OwinHostController.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; +using System.Reflection; using Microsoft.Owin.Hosting; using NLog; using NzbDrone.Common.EnvironmentInfo; @@ -50,7 +52,26 @@ namespace NzbDrone.Host.Owin _logger.Info("starting server on {0}", _urlAclAdapter.UrlAcl); - _host = WebApp.Start(OwinServiceProviderFactory.Create(), options, BuildApp); + try + { + _host = WebApp.Start(OwinServiceProviderFactory.Create(), options, BuildApp); + } + catch (TargetInvocationException ex) + { + if (ex.InnerException == null) + { + throw ex; + } + + if (ex.InnerException as HttpListenerException == null) + { + throw ex; + } + + throw new PortInUseException("Port {0} is already in use, please ensure NzbDrone is not already running.", + ex, + _configFileProvider.Port); + } } private void BuildApp(IAppBuilder appBuilder) diff --git a/NzbDrone.Host/Owin/PortInUseException.cs b/NzbDrone.Host/Owin/PortInUseException.cs new file mode 100644 index 000000000..5f6ea8f48 --- /dev/null +++ b/NzbDrone.Host/Owin/PortInUseException.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NzbDrone.Common.Exceptions; + +namespace NzbDrone.Host.Owin +{ + public class PortInUseException : NzbDroneException + { + public PortInUseException(string message, Exception innerException, params object[] args) : base(message, innerException, args) + { + } + } +}