public void Start()
{
var allServices = ServiceController.GetServices();
foreach( var service in RuntimeConfiguration.WindowsServices.Select(
s => {
var serviceController = allServices.SingleOrDefault( sc => sc.ServiceName == s.InstalledName );
if( serviceController == null ) {
throw new UserCorrectableException(
"The \"" + s.InstalledName + "\" service could not be found. Re-install the services for the installation to correct this error." );
}
return serviceController;
} ) ) {
try {
service.Start();
}
catch( InvalidOperationException e ) {
const string message = "Failed to start service.";
// We have seen this happen when an exception was thrown while initializing global logic for the system.
if( e.InnerException is Win32Exception &&
e.InnerException.Message.Contains( "The service did not respond to the start or control request in a timely fashion" ) )
throw new UserCorrectableException( message, e );
throw new ApplicationException( message, e );
}
service.WaitForStatusWithTimeOut( ServiceControllerStatus.Running );
// Set failure actions.
const int restartDelay = 60000; // milliseconds
EwlStatics.RunProgram(
"sc",
"failure \"{0}\" reset= {1} actions= restart/{2}".FormatWith( service.ServiceName, serviceFailureResetPeriod, restartDelay ),
"",
true );
EwlStatics.RunProgram( "sc", "failureflag \"{0}\" 1".FormatWith( service.ServiceName ), "", true );
}
if( runtimeConfiguration.InstallationType != InstallationType.Development ) {
foreach( var site in runtimeConfiguration.WebSiteNames )
startWebSite( site );
}
}