diff --git a/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs b/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs
index d45f4269f..3f470a963 100644
--- a/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs
+++ b/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs
@@ -1,9 +1,6 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
using System.Security.AccessControl;
using System.Security.Principal;
-using System.Text;
using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Instrumentation;
diff --git a/src/NzbDrone.Common/NzbDrone.Common.csproj b/src/NzbDrone.Common/NzbDrone.Common.csproj
index 086bd8d80..b2dd6301f 100644
--- a/src/NzbDrone.Common/NzbDrone.Common.csproj
+++ b/src/NzbDrone.Common/NzbDrone.Common.csproj
@@ -103,6 +103,7 @@
+
diff --git a/src/NzbDrone.Common/Processes/PidFileProvider.cs b/src/NzbDrone.Common/Processes/PidFileProvider.cs
new file mode 100644
index 000000000..c72832a68
--- /dev/null
+++ b/src/NzbDrone.Common/Processes/PidFileProvider.cs
@@ -0,0 +1,44 @@
+using System;
+using System.IO;
+using NLog;
+using NzbDrone.Common.EnvironmentInfo;
+
+namespace NzbDrone.Common.Processes
+{
+ public interface IProvidePidFile
+ {
+ void Write();
+ }
+
+ public class PidFileProvider : IProvidePidFile
+ {
+ private readonly IAppFolderInfo _appFolderInfo;
+ private readonly IProcessProvider _processProvider;
+ private readonly Logger _logger;
+
+ public PidFileProvider(IAppFolderInfo appFolderInfo, IProcessProvider processProvider, Logger logger)
+ {
+ _appFolderInfo = appFolderInfo;
+ _processProvider = processProvider;
+ _logger = logger;
+ }
+
+ public void Write()
+ {
+ var filename = Path.Combine(_appFolderInfo.AppDataFolder, "nzbdrone.pid");
+
+ if (OsInfo.IsMono)
+ {
+ try
+ {
+ File.WriteAllText(filename, _processProvider.GetCurrentProcess().Id.ToString());
+ }
+ catch (Exception ex)
+ {
+ _logger.Error("Unable to write PID file: " + filename, ex);
+ throw;
+ }
+ }
+ }
+ }
+}
diff --git a/src/NzbDrone.Host/ApplicationServer.cs b/src/NzbDrone.Host/ApplicationServer.cs
index c299c4870..c76fcc75c 100644
--- a/src/NzbDrone.Host/ApplicationServer.cs
+++ b/src/NzbDrone.Host/ApplicationServer.cs
@@ -24,7 +24,6 @@ namespace NzbDrone.Host
private readonly PriorityMonitor _priorityMonitor;
private readonly IStartupContext _startupContext;
private readonly IBrowserService _browserService;
- private readonly IProcessProvider _processProvider;
private readonly Logger _logger;
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider,
@@ -33,7 +32,6 @@ namespace NzbDrone.Host
PriorityMonitor priorityMonitor,
IStartupContext startupContext,
IBrowserService browserService,
- IProcessProvider processProvider,
Logger logger)
{
_configFileProvider = configFileProvider;
@@ -42,7 +40,6 @@ namespace NzbDrone.Host
_priorityMonitor = priorityMonitor;
_startupContext = startupContext;
_browserService = browserService;
- _processProvider = processProvider;
_logger = logger;
}
diff --git a/src/NzbDrone.Host/Bootstrap.cs b/src/NzbDrone.Host/Bootstrap.cs
index ca277851c..66bbe0cf3 100644
--- a/src/NzbDrone.Host/Bootstrap.cs
+++ b/src/NzbDrone.Host/Bootstrap.cs
@@ -34,6 +34,7 @@ namespace NzbDrone.Host
_container = MainAppContainerBuilder.BuildContainer(startupContext);
_container.Resolve().Register();
+ _container.Resolve().Write();
var appMode = GetApplicationMode(startupContext);