aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/zenutil/service.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/zenutil/service.cpp b/src/zenutil/service.cpp
index a2ff93efd..760e52baf 100644
--- a/src/zenutil/service.cpp
+++ b/src/zenutil/service.cpp
@@ -436,6 +436,8 @@ InstallService(std::string_view ServiceName, const ServiceSpec& Spec)
return MakeErrorCodeFromLastError();
}
+ auto _ = MakeGuard([schService]() { CloseServiceHandle(schService); });
+
if (!Spec.Description.empty())
{
ExtendableWideStringBuilder<128> DescriptionBuilder;
@@ -449,7 +451,24 @@ InstallService(std::string_view ServiceName, const ServiceSpec& Spec)
}
}
- CloseServiceHandle(schService);
+ // Actions defining what the service manager should do in the event of a zenserver crash.
+ // Attempt an immediate restart twice. If both restarts fail, stop trying.
+ // The attempt count will be reset based on the timeout specified in SERVICE_FAILURE_ACTIONS.
+ // If the service manages to survive for the length of that timeout, the reset attempt count
+ // will be reset and we will try restarting if we fail again.
+ SC_ACTION Actions[] = {{SC_ACTION_RESTART, 0}, {SC_ACTION_RESTART, 0}, {SC_ACTION_NONE, 0}};
+
+ SERVICE_FAILURE_ACTIONS FailureAction = {
+ 60, // if we haven't failed for one minute, assume the service is healthy and reset the failure count
+ NULL, // no reboot message - we don't want to reboot the whole system if zen dies
+ NULL, // no command to run on failure - just attempt restarting the service
+ ZEN_ARRAY_COUNT(Actions),
+ Actions};
+
+ if (!ChangeServiceConfig2(schService, SERVICE_CONFIG_FAILURE_ACTIONS, &FailureAction))
+ {
+ return MakeErrorCodeFromLastError();
+ }
return {};
}