Merge pull request #104 from zone117x/develop

Command line args.  Supercede pull #102 from sdesbure:master
This commit is contained in:
KZ 2015-07-24 00:09:32 +01:00
commit e71eaa9c97
9 changed files with 194 additions and 43 deletions

View File

@ -49,12 +49,12 @@ Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks:
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
[Run]
Filename: "{app}\JackettConsole.exe"; Parameters: "/u"; Flags: waituntilterminated;
Filename: "{app}\JackettConsole.exe"; Parameters: "/r"; Flags: waituntilterminated;
Filename: "{app}\JackettConsole.exe"; Parameters: "/i"; Flags: waituntilterminated; Tasks: windowsService
Filename: "{app}\JackettConsole.exe"; Parameters: "/start"; Flags: waituntilterminated; Tasks: windowsService
Filename: "{app}\JackettConsole.exe"; Parameters: "--Uninstall"; Flags: waituntilterminated;
Filename: "{app}\JackettConsole.exe"; Parameters: "--ReserveUrls"; Flags: waituntilterminated;
Filename: "{app}\JackettConsole.exe"; Parameters: "--Install"; Flags: waituntilterminated; Tasks: windowsService
Filename: "{app}\JackettConsole.exe"; Parameters: "--Start"; Flags: waituntilterminated; Tasks: windowsService
[UninstallRun]
Filename: "{app}\JackettConsole.exe"; Parameters: "/u"; Flags: waituntilterminated skipifdoesntexist
Filename: "{app}\JackettConsole.exe"; Parameters: "--Uninstall"; Flags: waituntilterminated skipifdoesntexist

View File

@ -0,0 +1,51 @@
using CommandLine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Jackett.Console
{
public class ConsoleOptions
{
private bool listenPublic = false;
[Option('i', "Install", HelpText = "Install Jackett windows service (Must be admin)")]
public bool Install { get; set; }
[Option('r', "ReserveUrls", HelpText = "(Re)Register windows port reservations (Required for listening on all interfaces).")]
public bool ReserveUrls { get; set; }
[Option('u', "Uninstall", HelpText = "Uninstall Jackett windows service (Must be admin).")]
public bool Uninstall { get; set; }
[Option('l', "Logging", DefaultValue = false, HelpText = "Log all requests/responses to Jackett")]
public bool Logging { get; set; }
[Option('t', "Tracing", DefaultValue = false, HelpText = "Enable tracing")]
public bool Tracing { get; set; }
[Option('c', "UseCurlExec", DefaultValue = false, HelpText = "Execute curl rather than libcurl for all outgoing requests.")]
public bool UseCurlExec { get; set; }
[Option('s', "Start", HelpText = "Start the Jacket Windows service (Must be admin)")]
public bool StartService { get; set; }
[Option('k', "Stop", HelpText = "Stop the Jacket Windows service (Must be admin)")]
public bool StopService { get; set; }
[Option('l', "ListenPublic", HelpText = "Listen publicly")]
public bool? ListenPublic { get; set; }
[Option('h', "Help", HelpText = "Show Help")]
public bool ShowHelp { get; set; }
[Option('v', "Version", HelpText = "Show Version")]
public bool ShowVersion { get; set; }
[Option('p', "Port", HelpText = "Web server port")]
public int Port { get; set; }
}
}

View File

@ -55,6 +55,10 @@
<Reference Include="Autofac.Integration.WebApi.Owin">
<HintPath>..\packages\Autofac.WebApi2.Owin.3.2.0\lib\net45\Autofac.Integration.WebApi.Owin.dll</HintPath>
</Reference>
<Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.Core">
<HintPath>..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
</Reference>
@ -127,6 +131,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConsoleOptions.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

View File

@ -1,5 +1,9 @@
using Jackett;
using CommandLine;
using CommandLine.Text;
using Jackett;
using Jackett.Console;
using Jackett.Indexers;
using Jackett.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -18,44 +22,132 @@ namespace JackettConsole
{
try
{
foreach (var arg in args)
var options = new ConsoleOptions();
if (!Parser.Default.ParseArguments(args, options) || options.ShowHelp == true)
{
switch (arg.ToLowerInvariant())
var text = HelpText.AutoBuild(options, (HelpText current) => HelpText.DefaultParsingErrorsHandler(options, current));
text.Copyright = " ";
text.Heading = "Jackett v" + Engine.ConfigService.GetVersion() + " options:";
Console.WriteLine(text);
Environment.ExitCode = 1;
return;
}
else
{
/* ====== Actions ===== */
// Install service
if (options.Install)
{
case "/i": // Install
Engine.ServiceConfig.Install();
return;
case "/r": // Reserve port/url & install
Engine.Server.ReserveUrls(doInstall: true);
return;
case "/c": // Change port
Engine.Server.ReserveUrls(doInstall: false);
return;
case "/u": // Uninstall
Engine.Server.ReserveUrls(doInstall: false);
Engine.ServiceConfig.Uninstall();
return;
case "/l": // Logging
Startup.LogRequests = true;
break;
case "/t": // Tracing
Startup.TracingEnabled = true;
break;
case "/curlsafe": // Curl safe mode
Startup.CurlSafe = true;
break;
case "/start": // Start Service
if (!Engine.ServiceConfig.ServiceRunning())
Engine.ServiceConfig.Install();
return;
}
// Uninstall service
if (options.Uninstall)
{
Engine.Server.ReserveUrls(doInstall: false);
Engine.ServiceConfig.Uninstall();
return;
}
// Reserve urls
if (options.ReserveUrls)
{
Engine.Server.ReserveUrls(doInstall: true);
return;
}
// Start Service
if (options.StartService)
{
if (!Engine.ServiceConfig.ServiceRunning())
{
Engine.ServiceConfig.Start();
}
return;
}
// Stop Service
if (options.StopService)
{
if (Engine.ServiceConfig.ServiceRunning())
{
Engine.ServiceConfig.Stop();
}
return;
}
// Show Version
if (options.ShowVersion)
{
Console.WriteLine("Jackett v" + Engine.ConfigService.GetVersion());
return;
}
/* ====== Options ===== */
// Logging
if (options.Logging)
{
Startup.LogRequests = true;
}
// Tracing
if (options.Tracing)
{
Startup.TracingEnabled = true;
}
// Use curl
if (options.UseCurlExec)
{
Startup.CurlSafe = true;
}
// Override listen public
if(options.ListenPublic.HasValue)
{
if(Engine.Server.Config.AllowExternal != options.ListenPublic)
{
Engine.Server.Config.AllowExternal = options.ListenPublic.Value;
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{
Engine.ServiceConfig.Start();
if (ServerUtil.IsUserAdministrator())
{
Engine.Server.ReserveUrls(doInstall: true);
}
else
{
Engine.Logger.Error("Unable to switch to public listening without admin rights.");
Environment.ExitCode = 1;
return;
}
}
return;
case "/stop": // Stop Service
if (Engine.ServiceConfig.ServiceRunning())
}
}
// Override port
if(options.Port != 0)
{
if (Engine.Server.Config.Port != options.Port)
{
Engine.Server.Config.Port = options.Port;
if (System.Environment.OSVersion.Platform != PlatformID.Unix)
{
Engine.ServiceConfig.Stop();
if (ServerUtil.IsUserAdministrator())
{
Engine.Server.ReserveUrls(doInstall: true);
}
else
{
Engine.Logger.Error("Unable to switch ports when not running as administrator");
Environment.ExitCode = 1;
return;
}
}
return;
}
}
}

View File

@ -4,6 +4,7 @@
<package id="Autofac.Owin" version="3.1.0" targetFramework="net452" />
<package id="Autofac.WebApi2" version="3.4.0" targetFramework="net452" />
<package id="Autofac.WebApi2.Owin" version="3.2.0" targetFramework="net452" />
<package id="CommandLineParser" version="1.9.71" targetFramework="net452" />
<package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />

View File

@ -141,7 +141,7 @@ namespace JackettTray
{
try
{
Engine.ProcessService.StartProcessAndLog(consolePath, "/stop", true);
Engine.ProcessService.StartProcessAndLog(consolePath, "--Stop", true);
}
catch
{
@ -159,7 +159,7 @@ namespace JackettTray
{
try
{
Engine.ProcessService.StartProcessAndLog(consolePath, "/start", true);
Engine.ProcessService.StartProcessAndLog(consolePath, "--Start", true);
}
catch
{

View File

@ -306,7 +306,7 @@ namespace Jackett.Controllers
if (!ServerUtil.IsUserAdministrator())
{
try {
processService.StartProcessAndLog(Application.ExecutablePath, "/r", true);
processService.StartProcessAndLog(Application.ExecutablePath, "--ReserveUrls", true);
}
catch
{

View File

@ -19,7 +19,7 @@ namespace Jackett
static Engine()
{
BuildContainer();
Logger.Info("Starting Jackett " + ConfigService.GetVersion());
}
public static void BuildContainer()
@ -121,8 +121,9 @@ namespace Jackett
var logFileRule = new LoggingRule("*", LogLevel.Info, logFile);
logConfig.LoggingRules.Add(logFileRule);
var logConsole = new ConsoleTarget();
var logConsole = new ColoredConsoleTarget();
logConfig.AddTarget("console", logConsole);
logConsole.Layout = "${longdate} ${level} ${message} ${exception:format=ToString}";
var logConsoleRule = new LoggingRule("*", Startup.TracingEnabled ? LogLevel.Debug : LogLevel.Info, logConsole);
logConfig.LoggingRules.Add(logConsoleRule);

View File

@ -103,6 +103,7 @@ namespace Jackett.Services
public void Initalize()
{
logger.Info("Starting Jackett " + configService.GetVersion());
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
// Allow all SSL.. sucks I know but mono on linux is having problems without it..