2017-09-27 02:06:05 +00:00
|
|
|
using System;
|
2014-04-28 05:14:31 +00:00
|
|
|
using System.IO;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2017-10-29 03:49:54 +00:00
|
|
|
using NzbDrone.Common.Exceptions;
|
2014-04-28 05:14:31 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Common.Processes
|
|
|
|
{
|
|
|
|
public interface IProvidePidFile
|
|
|
|
{
|
|
|
|
void Write();
|
|
|
|
}
|
|
|
|
|
|
|
|
public class PidFileProvider : IProvidePidFile
|
|
|
|
{
|
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2021-04-26 18:07:16 +00:00
|
|
|
public PidFileProvider(IAppFolderInfo appFolderInfo, Logger logger)
|
2014-04-28 05:14:31 +00:00
|
|
|
{
|
|
|
|
_appFolderInfo = appFolderInfo;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Write()
|
|
|
|
{
|
2014-12-07 20:54:07 +00:00
|
|
|
if (OsInfo.IsWindows)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-04-28 05:14:31 +00:00
|
|
|
|
2017-09-27 02:06:05 +00:00
|
|
|
var filename = Path.Combine(_appFolderInfo.AppDataFolder, "lidarr.pid");
|
2014-12-07 20:54:07 +00:00
|
|
|
try
|
|
|
|
{
|
2021-04-26 18:07:16 +00:00
|
|
|
File.WriteAllText(filename, ProcessProvider.GetCurrentProcessId().ToString());
|
2014-12-07 20:54:07 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
2014-04-28 05:14:31 +00:00
|
|
|
{
|
2017-01-05 23:32:17 +00:00
|
|
|
_logger.Error(ex, "Unable to write PID file {0}", filename);
|
2017-10-29 03:49:54 +00:00
|
|
|
throw new LidarrStartupException(ex, "Unable to write PID file {0}", filename);
|
2014-04-28 05:14:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|