aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil/service.cpp
diff options
context:
space:
mode:
authorLiam Mitchell <[email protected]>2025-03-26 15:23:08 -0700
committerGitHub Enterprise <[email protected]>2025-03-26 15:23:08 -0700
commitb495934423c5900911198528fd0c0ee1e3bdf309 (patch)
treee7e281e84c55828d8746ab4aabdc92bdd976cf99 /src/zenutil/service.cpp
parentMerge remote-tracking branch 'origin/main' into de/zen-service-command (diff)
parentAvoid leaking service handle in Windows service installation (diff)
downloadzen-b495934423c5900911198528fd0c0ee1e3bdf309.tar.xz
zen-b495934423c5900911198528fd0c0ee1e3bdf309.zip
Merge pull request #323 from ue-foundation/lm/zen-service-restart-options
Specify restart options for service manager, to avoid use of manual restart logic
Diffstat (limited to 'src/zenutil/service.cpp')
-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 {};
}