mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Add PIDFile CLI option
This commit is contained in:
@@ -12,6 +12,7 @@ using NLog.Config;
|
|||||||
using NLog.LayoutRenderers;
|
using NLog.LayoutRenderers;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -41,6 +42,20 @@ namespace Jackett
|
|||||||
builder.RegisterModule(module);
|
builder.RegisterModule(module);
|
||||||
}
|
}
|
||||||
container = builder.Build();
|
container = builder.Build();
|
||||||
|
|
||||||
|
// create PID file early
|
||||||
|
if (!string.IsNullOrWhiteSpace(settings.PIDFile))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var proc = Process.GetCurrentProcess();
|
||||||
|
File.WriteAllText(settings.PIDFile, proc.Id.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Error(e, "Error while creating the PID file");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void InitAutomapper()
|
private static void InitAutomapper()
|
||||||
@@ -220,6 +235,30 @@ namespace Jackett
|
|||||||
LogManager.ReconfigExistingLoggers();
|
LogManager.ReconfigExistingLoggers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Exit(int exitCode)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Engine.ServerConfig != null &&
|
||||||
|
Engine.ServerConfig.RuntimeSettings != null &&
|
||||||
|
!string.IsNullOrWhiteSpace(Engine.ServerConfig.RuntimeSettings.PIDFile))
|
||||||
|
{
|
||||||
|
var PIDFile = Engine.ServerConfig.RuntimeSettings.PIDFile;
|
||||||
|
if (File.Exists(PIDFile))
|
||||||
|
{
|
||||||
|
Engine.Logger.Info("Deleting PID file " + PIDFile);
|
||||||
|
File.Delete(PIDFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Error(e, "Error while deleting the PID file");
|
||||||
|
}
|
||||||
|
|
||||||
|
Environment.Exit(exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
public static void SaveServerConfig()
|
public static void SaveServerConfig()
|
||||||
{
|
{
|
||||||
ConfigService.SaveConfig(ServerConfig);
|
ConfigService.SaveConfig(ServerConfig);
|
||||||
|
@@ -64,9 +64,10 @@ namespace Jackett.Common.Models.Config
|
|||||||
public string DataFolder { get; set; }
|
public string DataFolder { get; set; }
|
||||||
|
|
||||||
[Option("NoRestart", HelpText = "Don't restart after update")]
|
[Option("NoRestart", HelpText = "Don't restart after update")]
|
||||||
public bool NoRestart { get; set; }
|
public bool NoRestart { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[Option("PIDFile", HelpText = "Specify the location of PID file")]
|
||||||
|
public string PIDFile { get; set; }
|
||||||
|
|
||||||
public RuntimeSettings ToRunTimeSettings()
|
public RuntimeSettings ToRunTimeSettings()
|
||||||
{
|
{
|
||||||
@@ -83,7 +84,7 @@ namespace Jackett.Common.Models.Config
|
|||||||
if (options.ListenPublic && options.ListenPrivate)
|
if (options.ListenPublic && options.ListenPrivate)
|
||||||
{
|
{
|
||||||
Console.WriteLine("You can only use listen private OR listen publicly.");
|
Console.WriteLine("You can only use listen private OR listen publicly.");
|
||||||
Environment.Exit(1);
|
Engine.Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SSL Fix
|
// SSL Fix
|
||||||
@@ -105,6 +106,8 @@ namespace Jackett.Common.Models.Config
|
|||||||
if (!string.IsNullOrWhiteSpace(options.DataFolder))
|
if (!string.IsNullOrWhiteSpace(options.DataFolder))
|
||||||
runtimeSettings.CustomDataFolder = options.DataFolder;
|
runtimeSettings.CustomDataFolder = options.DataFolder;
|
||||||
|
|
||||||
|
runtimeSettings.PIDFile = options.PIDFile;
|
||||||
|
|
||||||
return runtimeSettings;
|
return runtimeSettings;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,9 @@ namespace Jackett.Common.Models.Config
|
|||||||
|
|
||||||
public string CustomLogFileName { get; set; }
|
public string CustomLogFileName { get; set; }
|
||||||
|
|
||||||
|
public string PIDFile { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public string DataFolder
|
public string DataFolder
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@@ -257,7 +257,7 @@ namespace Jackett.Services
|
|||||||
private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart)
|
private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart)
|
||||||
{
|
{
|
||||||
var exe = Path.GetFileName(ExePath());
|
var exe = Path.GetFileName(ExePath());
|
||||||
var args = string.Join(" ", Environment.GetCommandLineArgs().Skip(1));
|
var args = string.Join(" ", Environment.GetCommandLineArgs().Skip(1).Select(a => a.Contains(" ") ? "\"" +a + "\"" : a )).Replace("\"", "\\\"");
|
||||||
|
|
||||||
var startInfo = new ProcessStartInfo();
|
var startInfo = new ProcessStartInfo();
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ namespace Jackett.Services
|
|||||||
{
|
{
|
||||||
logger.Info("Exiting Jackett..");
|
logger.Info("Exiting Jackett..");
|
||||||
lockService.Signal();
|
lockService.Signal();
|
||||||
Environment.Exit(0);
|
Engine.Exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -152,7 +152,7 @@ namespace JackettConsole
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Engine.Logger.Error("Unable to switch to public listening without admin rights.");
|
Engine.Logger.Error("Unable to switch to public listening without admin rights.");
|
||||||
Environment.Exit(1);
|
Engine.Exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ namespace JackettConsole
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Engine.Logger.Error("Unable to switch ports when not running as administrator");
|
Engine.Logger.Error("Unable to switch ports when not running as administrator");
|
||||||
Environment.Exit(1);
|
Engine.Exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -144,7 +144,7 @@ namespace Jackett.Services
|
|||||||
if (monoVersionO.Major < 4)
|
if (monoVersionO.Major < 4)
|
||||||
{
|
{
|
||||||
logger.Error("Your mono version is to old (mono 3 is no longer supported). Please update to the latest version from http://www.mono-project.com/download/");
|
logger.Error("Your mono version is to old (mono 3 is no longer supported). Please update to the latest version from http://www.mono-project.com/download/");
|
||||||
Environment.Exit(2);
|
Engine.Exit(2);
|
||||||
}
|
}
|
||||||
else if (monoVersionO.Major == 4 && monoVersionO.Minor == 2)
|
else if (monoVersionO.Major == 4 && monoVersionO.Minor == 2)
|
||||||
{
|
{
|
||||||
@@ -202,7 +202,7 @@ namespace Jackett.Services
|
|||||||
{
|
{
|
||||||
logger.Debug(e);
|
logger.Debug(e);
|
||||||
logger.Error(e.Message + " Most likely the mono-locale-extras package is not installed.");
|
logger.Error(e.Message + " Most likely the mono-locale-extras package is not installed.");
|
||||||
Environment.Exit(2);
|
Engine.Exit(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,12 +249,12 @@ namespace Jackett.Services
|
|||||||
if (inner is SocketException && ((SocketException)inner).SocketErrorCode == SocketError.AddressAlreadyInUse) // Linux (mono)
|
if (inner is SocketException && ((SocketException)inner).SocketErrorCode == SocketError.AddressAlreadyInUse) // Linux (mono)
|
||||||
{
|
{
|
||||||
logger.Error("Address already in use: Most likely Jackett is already running.");
|
logger.Error("Address already in use: Most likely Jackett is already running.");
|
||||||
Environment.Exit(1);
|
Engine.Exit(1);
|
||||||
}
|
}
|
||||||
else if (inner is HttpListenerException && ((HttpListenerException)inner).ErrorCode == 183) // Windows
|
else if (inner is HttpListenerException && ((HttpListenerException)inner).ErrorCode == 183) // Windows
|
||||||
{
|
{
|
||||||
logger.Error(inner.Message + " Most likely Jackett is already running.");
|
logger.Error(inner.Message + " Most likely Jackett is already running.");
|
||||||
Environment.Exit(1);
|
Engine.Exit(1);
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user