Skip to content

Commit 29dfe17

Browse files
author
Greg Bielleman
committed
Add a DB maintenance mode to ServiceControl
Added the-maintenance command line switch to allow ServiceControl to be started with reduced functionality. In this mode it serves up the RavenDB Web UI but disables the Raven Bundles and the periodic deletion code and does not start the bus so message processing and the REST API are also disabled.
1 parent 8b5b473 commit 29dfe17

File tree

7 files changed

+74
-15
lines changed

7 files changed

+74
-15
lines changed

src/ServiceControl/Bootstrapper.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class Bootstrapper
2222
IStartableBus bus;
2323
public static IContainer Container { get; set; }
2424

25+
2526
public Bootstrapper(ServiceBase host = null, HostArguments hostArguments = null)
2627
{
2728
Settings.ServiceName = DetermineServiceName(host, hostArguments);
@@ -81,6 +82,18 @@ static bool IsExternalContract(Type t)
8182

8283
public void Start()
8384
{
85+
var Logger = NServiceBus.Logging.LogManager.GetLogger(typeof(Bootstrapper));
86+
if (Settings.MaintenanceMode)
87+
{
88+
Logger.InfoFormat("RavenDB is now accepting requests on {0}", Settings.StorageUrl);
89+
Logger.Warn("RavenDB Maintenance Mode - Press Enter to exit");
90+
while (Console.ReadLine() == null)
91+
{
92+
}
93+
return;
94+
}
95+
96+
8497
bus.Start(() =>
8598
{
8699
if (Environment.UserInteractive && Debugger.IsAttached)
@@ -123,11 +136,6 @@ static void ConfigureLogging()
123136
nlogConfig.LoggingRules.Add(new LoggingRule("Raven.*", LogLevel.Warn, fileTarget));
124137
nlogConfig.LoggingRules.Add(new LoggingRule("Raven.*", LogLevel.Warn, consoleTarget) { Final = true });
125138
nlogConfig.LoggingRules.Add(new LoggingRule("Particular.ServiceControl.Licensing.*", LogLevel.Info, fileTarget));
126-
127-
#if (DEBUG) //TODO : Remove once we've stabilized deletions
128-
nlogConfig.LoggingRules.Add(new LoggingRule("ServiceControl.Infrastructure.RavenDB.Expiration.*", LogLevel.Debug, consoleTarget));
129-
nlogConfig.LoggingRules.Add(new LoggingRule("ServiceControl.Infrastructure.RavenDB.Expiration.*", LogLevel.Debug, fileTarget));
130-
#endif
131139
nlogConfig.LoggingRules.Add(new LoggingRule("NServiceBus.Licensing.*", LogLevel.Error, fileTarget));
132140
nlogConfig.LoggingRules.Add(new LoggingRule("NServiceBus.Licensing.*", LogLevel.Error, consoleTarget) { Final = true });
133141
nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Warn, fileTarget));
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace ServiceControl.Hosting.Commands
2+
{
3+
using Particular.ServiceControl;
4+
using Particular.ServiceControl.Commands;
5+
using Particular.ServiceControl.Hosting;
6+
7+
class MaintCommand : AbstractCommand
8+
{
9+
Bootstrapper bootstrapper;
10+
11+
public override void Execute(HostArguments args)
12+
{
13+
bootstrapper = new Bootstrapper(null, args);
14+
bootstrapper.Start();
15+
}
16+
}
17+
}

src/ServiceControl/Hosting/Help.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ USAGE:
66
ServiceControl.exe --restart [options]
77
ServiceControl.exe --install [options]
88
ServiceControl.exe --uninstall [options]
9+
ServiceControl.exe --maintenance [options]
910

1011
DEFAULT OPTIONS:
1112

@@ -19,6 +20,13 @@ UNINSTALL OPTIONS:
1920

2021
{2}
2122

23+
MAINTENANCE
24+
25+
The maintenance switch allows RavenDB Maintenance tasks to be carried out. In this mode ServiceControl enables the RavenDB Web UI only.
26+
The REST API, message importers and the background document expiry are all disabled.
27+
28+
This mode is only supported when run interactively.
29+
2230
CONFIGURATION OPTIONS:
2331

2432
ServiceControl/LogPath string

src/ServiceControl/Hosting/HostArguments.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Particular.ServiceControl.Hosting
88
using System.Text;
99
using Commands;
1010
using global::ServiceControl.Hosting.Commands;
11+
using ServiceBus.Management.Infrastructure.Settings;
1112

1213
public class HostArguments
1314
{
@@ -79,9 +80,25 @@ public HostArguments(string[] args)
7980
"serviceName=",
8081
@"Specify the service name for the installed service."
8182
, s => { ServiceName = s; }
83+
},
84+
};
85+
86+
maintenanceOptions = new OptionSet
87+
{
88+
{
89+
"m|maint|maintenance",
90+
@"Run RavenDB only - use for DB maintenance",
91+
s => {
92+
commands = new List<Type>
93+
{
94+
typeof(MaintCommand)
95+
};
96+
executionMode = ExecutionMode.Maintenance;
97+
}
8298
}
8399
};
84100

101+
85102
uninstallOptions = new OptionSet
86103
{
87104
{
@@ -103,8 +120,6 @@ public HostArguments(string[] args)
103120
}
104121
};
105122

106-
107-
108123
installOptions = new OptionSet
109124
{
110125
{
@@ -207,6 +222,12 @@ public HostArguments(string[] args)
207222
{
208223
return;
209224
}
225+
maintenanceOptions.Parse(args);
226+
if (executionMode == ExecutionMode.Maintenance)
227+
{
228+
Settings.MaintenanceMode = true;
229+
return;
230+
}
210231

211232
defaultOptions.Parse(args);
212233
}
@@ -278,6 +299,7 @@ public void PrintUsage()
278299
readonly OptionSet installOptions;
279300
readonly OptionSet uninstallOptions;
280301
readonly OptionSet defaultOptions;
302+
readonly OptionSet maintenanceOptions;
281303
List<Type> commands;
282304
Dictionary<string, string> options = new Dictionary<string, string>();
283305
StartMode startMode;
@@ -287,7 +309,8 @@ internal enum ExecutionMode
287309
{
288310
Install,
289311
Uninstall,
290-
Run
312+
Run,
313+
Maintenance
291314
}
292315

293316
public enum StartMode

src/ServiceControl/Infrastructure/RavenDB/RavenBootstrapper.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
public class RavenBootstrapper : INeedInitialization
1818
{
19-
2019
public static string ReadLicense()
2120
{
2221
using (var resourceStream = typeof(RavenBootstrapper).Assembly.GetManifestResourceStream("ServiceControl.Infrastructure.RavenDB.RavenLicense.xml"))
@@ -33,7 +32,7 @@ public void Init()
3332
var documentStore = new EmbeddableDocumentStore
3433
{
3534
DataDirectory = Settings.DbPath,
36-
UseEmbeddedHttpServer = Settings.ExposeRavenDB,
35+
UseEmbeddedHttpServer = Settings.MaintenanceMode || Settings.ExposeRavenDB,
3736
EnlistInDistributedTransactions = false,
3837
};
3938

@@ -48,19 +47,20 @@ public void Init()
4847
Logger.InfoFormat("Loading Embedded RavenDB license");
4948
documentStore.Configuration.Settings["Raven/License"] = ReadLicense();
5049
}
51-
50+
5251
documentStore.Configuration.Catalog.Catalogs.Add(new AssemblyCatalog(GetType().Assembly));
53-
documentStore.Configuration.Settings.Add("Raven/ActiveBundles", "CustomDocumentExpiration");
52+
53+
if (!Settings.MaintenanceMode) {
54+
documentStore.Configuration.Settings.Add("Raven/ActiveBundles", "CustomDocumentExpiration");
55+
}
56+
5457
documentStore.Configuration.Port = Settings.Port;
5558
documentStore.Configuration.HostName = (Settings.Hostname == "*" || Settings.Hostname == "+")
5659
? "localhost"
5760
: Settings.Hostname;
5861
documentStore.Configuration.CompiledIndexCacheDirectory = Settings.DbPath;
5962
documentStore.Configuration.VirtualDirectory = Settings.VirtualDirectory + "/storage";
60-
6163
documentStore.Conventions.SaveEnumsAsIntegers = true;
62-
63-
6464
documentStore.Initialize();
6565

6666
Logger.Info("Index creation started");

src/ServiceControl/Infrastructure/Settings/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ static Settings()
1818
TransportType = SettingsReader<string>.Read("TransportType", typeof(Msmq).AssemblyQualifiedName);
1919
}
2020

21+
public static bool MaintenanceMode;
22+
2123
public static string ApiUrl
2224
{
2325
get

src/ServiceControl/ServiceControl.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
<Compile Include="Hosting\Commands\AbstractCommand.cs" />
241241
<Compile Include="Hosting\Commands\CommandRunner.cs" />
242242
<Compile Include="Hosting\Commands\InstallCommand.cs" />
243+
<Compile Include="Hosting\Commands\MaintCommand.cs" />
243244
<Compile Include="Hosting\Commands\RestartCommand.cs" />
244245
<Compile Include="Hosting\Commands\RunBootstrapperAndNServiceBusInstallers.cs" />
245246
<Compile Include="Hosting\Commands\RunCommand.cs" />

0 commit comments

Comments
 (0)