|
|
|
|
// Startup off service? IF InServiceMode() = False _AND_ InTestMode() = False THEN // Startup off service: // this project being intended to be a service, // propose to install the service // Service installed? IF ServiceExist(gsServiceName) = False THEN // No IF YesNo("The service is not installed" + CR + ... "Do you want to install it now?") = True THEN // Parameters of the service // Startup Service.Startup = serviceStartupManual Service.DelayedStartup = False // "Normal" service Service.Type = serviceTypeSimple // Description Service.Description = "WINDEV WDService" Service.LongDescription = "WINDEV service that will be restarted in case of failure" // In case of error at startup, // information in the log of events Service.StartupError = serviceErrorLog // It is the current executable Service.CommandLine = ExeInfo(exeName) // Rights Service.User = AccountLocalSystem // In case of failure... // Wait during 3 seconds to give time // to the different resources of the service to be freed Service.TimeoutBeforeActionOnFailure = (3*1000) // The number of failures is reinitialized // after 30 seconds without a failure Service.ReinitFailureCounter = 30 // Number of authorized failures: 3 Service.NbActionOnFailure = 3 // First failure: The service restarts Service.ActionOnFailure[1] = serviceFailureRestartService // and for the following failures (4 in this example) // same action FOR nFailureNum = 2 _TO_ 3 Service.ActionOnFailure[nFailureNum] = ... serviceFailureRestartService END // Installs the service IF ServiceInstall(gsServiceName) = False THEN Error("Unable to install the service: '" + ErrorInfo()) ELSE // Starts the service IF ServiceStart(gsServiceName) = True THEN Info("The service was installed and started") ELSE Error("The service was installed but it cannot be started", ... ErrorInfo()) END END END ELSE // Yes // Service status nServiceStatus is int = ServiceStatus(gsServiceName) SWITCH nServiceStatus CASE -1 // Error Error("Unable to get the service status: ", ErrorInfo()) CASE serviceStatusStopped // Service stopped, let's restart it //1: Start it //2: Uninstall it //3: No action SWITCH Dialog("The service is currently stopped. What do you want to do?") // Start it CASE 1 // Starts the service IF ServiceStart(gsServiceName) = True THEN Info("The service was installed and started") ELSE Error("The service was installed" + ... "but it cannot be started", ... ErrorInfo()) END // Uninstall it CASE 2 IF ServiceUninstall(gsServiceName) = True THEN Info("The service was uninstalled") ELSE Error("The service was not uninstalled",... ErrorInfo()) END // No action CASE 3 END CASE serviceStatusStarted // Service already started, specify it IF YesNo("The service is already started" + ... "Do you want to stop it?") THEN IF ServiceStop(gsServiceName) = True THEN Info("The service was successfully stopped") ELSE Error("The service cannot be stopped", ErrorInfo()) END END OTHER CASE // Other status (waiting to be started, to be stopped...) SWITCH nServiceStatus CASE serviceStatusStopping Info("The service is being stopped " + ... "(a stop request was received " + ... "but it is not stopped yet)") CASE serviceStatusStarting Info("The service is being started " + ... "(a start request was received " + ... "but it is not started yet)") CASE serviceStatusPausing Info("The service is being paused " + ... "(a pause request was received " + ... "but it is not paused yet)") CASE serviceStatusRestarting Info("The service is being restarted " + ... "(a restart request was received" + ... "but is is not restarted yet)") CASE serviceStatusPaused IF YesNo("The service is currently paused, " + ... "Do you want to re-enable it?") THEN IF NOT ServiceContinue(gsServiceName) THEN Error("The service is paused" + ... "it cannot be restarted: ", ... ErrorInfo()) ELSE Info("The service was re-enabled") END END OTHER CASE Error("The service is in an unexpected status: " + ... nServiceStatus) END END END EndProgram() END
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|