Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Skovhede <kenneth@hexad.dk>2016-09-16 13:38:22 +0300
committerKenneth Skovhede <kenneth@hexad.dk>2016-09-16 13:38:22 +0300
commit274d1cfeadc85181e9af80624a7abf1d7f9cf0b2 (patch)
tree4e67733a46b449c0370059aed091f5c535e2eb15
parenta1ae050323daabafd36d0ed7a1e4d27e3da2be24 (diff)
parentafa9924f30f659b7581678d6140b81148ec53ddb (diff)
Merge branch 'feature/implement_self_install_windows_service'
-rw-r--r--Duplicati/Service/Runner.cs8
-rw-r--r--Duplicati/WindowsService/Program.cs45
-rw-r--r--Duplicati/WindowsService/ProjectInstaller.cs24
-rw-r--r--Duplicati/WindowsService/ServiceControl.cs11
-rw-r--r--Duplicati/WindowsService/ServiceProcessInstaller.cs13
5 files changed, 90 insertions, 11 deletions
diff --git a/Duplicati/Service/Runner.cs b/Duplicati/Service/Runner.cs
index 49a33a5ba..3eebff185 100644
--- a/Duplicati/Service/Runner.cs
+++ b/Duplicati/Service/Runner.cs
@@ -55,13 +55,9 @@ namespace Duplicati.Service
var self_exec = System.Reflection.Assembly.GetExecutingAssembly().Location;
var path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
var exec = System.IO.Path.Combine(path, "Duplicati.Server.exe");
- var cmdargs = Environment.CommandLine + " --ping-pong-keepalive=true";
+ var cmdargs = "--ping-pong-keepalive=true";
if (m_cmdargs != null && m_cmdargs.Length > 0)
- cmdargs = cmdargs + string.Join(" ", m_cmdargs);
-
- if (cmdargs.StartsWith(self_exec))
- cmdargs = cmdargs.Substring(self_exec.Length);
-
+ cmdargs = cmdargs + " " + string.Join(" ", m_cmdargs);
var firstRun = true;
var startAttempts = 0;
diff --git a/Duplicati/WindowsService/Program.cs b/Duplicati/WindowsService/Program.cs
index b646861eb..17483528a 100644
--- a/Duplicati/WindowsService/Program.cs
+++ b/Duplicati/WindowsService/Program.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
+using System.Configuration.Install;
using System.Linq;
+using System.Reflection;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
@@ -11,7 +13,48 @@ namespace Duplicati.WindowsService
{
public static void Main(string[] args)
{
- ServiceBase.Run(new ServiceBase[] { new ServiceControl(args) });
+ var install = args != null && args.Where(x => string.Equals("install", x, StringComparison.OrdinalIgnoreCase)).Any();
+ var uninstall = args != null && args.Where(x => string.Equals("uninstall", x, StringComparison.OrdinalIgnoreCase)).Any();
+ var help = args != null && args.Where(x => string.Equals("help", x, StringComparison.OrdinalIgnoreCase)).Any();
+
+ if (help)
+ {
+ Console.WriteLine("This is a Windows Service wrapper tool that hosts the Duplicati.Server.exe process, letting it run as a windows service.");
+ Console.WriteLine("|To run from a console, run the Duplicati.Server.exe instead of Duplicati.WindowsService.exe");
+ Console.WriteLine();
+ Console.WriteLine("Supported commands:");
+ Console.WriteLine(" install:\r\n Installs the service");
+ Console.WriteLine(" uninstall:\r\n Uninstalls the service");
+ Console.WriteLine();
+ Console.WriteLine("Supported options for the install command:");
+ Console.WriteLine(" /localuser:\r\n Installs the service as a local user");
+ Console.WriteLine();
+ Console.WriteLine("It is possible to pass arguments to Duplicati.Server.exe, simply add them to the commandline:");
+ Console.WriteLine(" Duplicati.WindowsService.exe install --webservice-interface=loopback --log-retention=3M");
+ Console.WriteLine();
+ Console.WriteLine("To see supported options, run Duplicati.Server.exe:");
+ Console.WriteLine(" Duplicati.Server.exe help");
+ Console.WriteLine();
+ Console.WriteLine("To debug the WindowsService setup, add the --debug-service:");
+ Console.WriteLine(" Duplicati.WindowsService.exe install --debug-service");
+ }
+ else if (install || uninstall)
+ {
+ // Remove the install and uninstall flags if they are present
+ var commandline = string.Join(" ", args.Where(x => !(string.Equals("install", x, StringComparison.OrdinalIgnoreCase) || string.Equals("uninstall", x, StringComparison.OrdinalIgnoreCase))));
+ var selfexec = Assembly.GetExecutingAssembly().Location;
+
+
+ // --uninstall + --install = reinstall
+ if (uninstall)
+ ManagedInstallerClass.InstallHelper(new string[] { "/u", selfexec });
+ if (install)
+ ManagedInstallerClass.InstallHelper(new string[] { "/commandline=" + commandline, selfexec });
+ }
+ else
+ {
+ ServiceBase.Run(new ServiceBase[] { new ServiceControl(args) });
+ }
}
}
}
diff --git a/Duplicati/WindowsService/ProjectInstaller.cs b/Duplicati/WindowsService/ProjectInstaller.cs
index 4ab6fb84d..eec0bf56b 100644
--- a/Duplicati/WindowsService/ProjectInstaller.cs
+++ b/Duplicati/WindowsService/ProjectInstaller.cs
@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
+using System.Text;
using System.Linq;
using System.Threading.Tasks;
@@ -18,5 +19,28 @@ namespace Duplicati.WindowsService
new ServiceInstaller()
});
}
+
+ public override void Install(IDictionary stateSaver)
+ {
+ var commandline = Context.Parameters["commandline"];
+ if (!string.IsNullOrWhiteSpace(commandline))
+ {
+ var rawpath = Context.Parameters["assemblypath"];
+ var path = new StringBuilder(rawpath);
+ if (!rawpath.StartsWith("\"", StringComparison.Ordinal) || !rawpath.EndsWith("\"", StringComparison.Ordinal))
+ {
+ path.Insert(0, '"');
+ path.Append('"');
+ }
+
+ path.Append(" ");
+ path.Append(commandline);
+
+ Context.Parameters["assemblypath"] = path.ToString();
+ }
+
+ base.Install(stateSaver);
+ }
+
}
}
diff --git a/Duplicati/WindowsService/ServiceControl.cs b/Duplicati/WindowsService/ServiceControl.cs
index 61133cd11..b6eddc9e0 100644
--- a/Duplicati/WindowsService/ServiceControl.cs
+++ b/Duplicati/WindowsService/ServiceControl.cs
@@ -33,9 +33,10 @@ namespace Duplicati.WindowsService
m_eventLog.Source = LOG_SOURCE;
m_eventLog.Log = LOG_NAME;
- m_cmdargs = args;
- m_verbose_messages = m_cmdargs != null && m_cmdargs.Where(x => string.Equals("--debug-service", x, StringComparison.OrdinalIgnoreCase)).Any();
- }
+ m_verbose_messages = args != null && args.Any(x => string.Equals("--debug-service", x, StringComparison.OrdinalIgnoreCase));
+ m_cmdargs = (args ?? new string[0]).Where(x => !string.Equals("--debug-service", x, StringComparison.OrdinalIgnoreCase)).ToArray();
+
+ }
protected override void OnStart(string[] args)
{
@@ -54,6 +55,8 @@ namespace Duplicati.WindowsService
private void DoStart(string[] args)
{
+ var startargs = (args ?? new string[0]).Union(m_cmdargs ?? new string[0]).ToArray();
+
if (m_verbose_messages)
m_eventLog.WriteEntry("Starting...");
lock(m_lock)
@@ -72,7 +75,7 @@ namespace Duplicati.WindowsService
m_eventLog.WriteEntry("Starting runner...");
m_runner = new Runner(
- m_cmdargs,
+ startargs,
() =>
{
if (m_verbose_messages)
diff --git a/Duplicati/WindowsService/ServiceProcessInstaller.cs b/Duplicati/WindowsService/ServiceProcessInstaller.cs
index 2537fdd57..cc90447ab 100644
--- a/Duplicati/WindowsService/ServiceProcessInstaller.cs
+++ b/Duplicati/WindowsService/ServiceProcessInstaller.cs
@@ -12,5 +12,18 @@ namespace Duplicati.WindowsService
{
this.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
}
+
+ public override void Install(System.Collections.IDictionary stateSaver)
+ {
+ var localuser = Context.Parameters["localuser"];
+ if (localuser != null)
+ {
+ this.Account = System.ServiceProcess.ServiceAccount.User;
+ this.Username = localuser;
+ }
+
+
+ base.Install(stateSaver);
+ }
}
}