Skip to content

Commit cb6fdbe

Browse files
committed
Merge branch 'develop'
2 parents 2268bfd + 3700691 commit cb6fdbe

File tree

9 files changed

+28
-20
lines changed

9 files changed

+28
-20
lines changed

src/ServiceControl/Bootstrapper.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Particular.ServiceControl
55
using System.IO;
66
using System.ServiceProcess;
77
using Autofac;
8+
using Hosting;
89
using NLog;
910
using NLog.Config;
1011
using NLog.Layouts;
@@ -20,14 +21,14 @@ public class Bootstrapper
2021
IStartableBus bus;
2122
public static IContainer Container { get; set; }
2223

23-
public Bootstrapper(ServiceBase host = null)
24+
public Bootstrapper(ServiceBase host = null, HostArguments hostArguments = null)
2425
{
25-
Settings.ServiceName = DetermineServiceName(host);
26+
Settings.ServiceName = DetermineServiceName(host, hostArguments);
2627
ConfigureLogging();
2728
var containerBuilder = new ContainerBuilder();
28-
29+
2930
Container = containerBuilder.Build();
30-
31+
3132
// Disable Auditing for the service control endpoint
3233
Configure.Features.Disable<Audit>();
3334
Configure.Features.Enable<Sagas>();
@@ -112,8 +113,15 @@ static void ConfigureLogging()
112113
LogManager.Configuration = nlogConfig;
113114
}
114115

115-
string DetermineServiceName(ServiceBase host)
116+
string DetermineServiceName(ServiceBase host, HostArguments hostArguments)
116117
{
118+
//if Arguments not null then bootstrapper was run from installer so use servicename passed to the installer
119+
if (hostArguments != null)
120+
{
121+
return hostArguments.ServiceName;
122+
}
123+
124+
// Try to get HostName from Windows Service Name, default to "Particular.ServiceControl"
117125
if ((host == null) || (string.IsNullOrWhiteSpace(host.ServiceName)))
118126
{
119127
return "Particular.ServiceControl";

src/ServiceControl/Hosting/Commands/RunBootstrapperAndNServiceBusInstallers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public override void Execute(HostArguments args)
99
{
1010
WindowsInstallerRunner.RunInstallers = true;
1111
WindowsInstallerRunner.RunAs = args.Username;
12-
new Bootstrapper();
12+
new Bootstrapper(null, args);
1313
}
1414
}
1515
}

src/ServiceControl/Hosting/Commands/RunCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ public override void Execute(HostArguments args)
1010
{
1111
if (!Environment.UserInteractive)
1212
{
13-
using (var service = new Host())
13+
using (var service = new Host{ServiceName = args.ServiceName})
1414
{
1515
service.Run();
1616
}
1717

1818
return;
1919
}
2020

21-
using (var service = new Host())
21+
using (var service = new Host{ ServiceName = args.ServiceName} )
2222
{
23+
24+
2325
using (var waitHandle = new ManualResetEvent(false))
2426
{
2527
service.OnStopping = () =>

src/ServiceControl/Hosting/Commands/ServiceCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void ExecuteInternal(HostArguments args)
3838
serviceProcessInstaller
3939
};
4040

41-
var arguments = String.Empty;
41+
var arguments = string.Format(" --serviceName:{0}", args.ServiceName);
4242

4343
using (var hostInstaller = new HostInstaller(args, arguments, installers))
4444
using (var transactedInstaller = new TransactedInstaller())

src/ServiceControl/Hosting/Help.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ EXAMPLES:
7878
--description="Service for monitoring"
7979
--username="corp\serviceuser"
8080
--password="p@ssw0rd!"
81-
--url="http://localhost:9090"
81+
--d=ServiceControl/Hostname==localhost
82+
--d=ServiceControl/Port==33334
8283

8384
ServiceControl.exe --uninstall --serviceName="MyServiceControl"

src/ServiceControl/Hosting/HostArguments.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Particular.ServiceControl.Hosting
99
using Commands;
1010
using global::ServiceControl.Hosting.Commands;
1111

12-
internal class HostArguments
12+
public class HostArguments
1313
{
1414
public HostArguments(string[] args)
1515
{
@@ -103,6 +103,8 @@ public HostArguments(string[] args)
103103
}
104104
};
105105

106+
107+
106108
installOptions = new OptionSet
107109
{
108110
{
@@ -288,7 +290,7 @@ internal enum ExecutionMode
288290
Run
289291
}
290292

291-
internal enum StartMode
293+
public enum StartMode
292294
{
293295
Manual,
294296
Automatic,

src/ServiceControl/Hosting/HostInstaller.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@ public override void Install(IDictionary stateSaver)
1919

2020
base.Install(stateSaver);
2121

22-
using (
23-
var service =
24-
Registry.LocalMachine.OpenSubKey(
25-
string.Format(@"System\CurrentControlSet\Services\{0}", settings.ServiceName), true))
22+
using (var service = Registry.LocalMachine.OpenSubKey(string.Format(@"System\CurrentControlSet\Services\{0}", settings.ServiceName), true))
2623
{
2724
var imagePath = (string) service.GetValue("ImagePath");
28-
2925
imagePath += arguments;
30-
3126
service.SetValue("ImagePath", imagePath);
3227
}
3328
}

src/ServiceControl/Infrastructure/Nancy/Modules/RootModule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public RootModule()
5050
Get["/instance-info"] = p => Negotiate
5151
.WithModel(new
5252
{
53+
WindowsService = Settings.ServiceName,
5354
LogfilePath = Path.Combine(Settings.LogPath, "logfile.txt"),
5455
Settings.TransportType,
5556
})

src/ServiceControl/Infrastructure/Settings/Settings.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ static string DefaultLogPathForInstance()
162162
{
163163
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Particular\\ServiceControl\\logs");
164164
}
165-
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
166-
string.Format("Particular\\ServiceControl-{0}\\logs", ServiceName));
165+
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), string.Format("Particular\\{0}\\logs", ServiceName));
167166

168167
}
169168
}

0 commit comments

Comments
 (0)