aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil/service.cpp
diff options
context:
space:
mode:
authorLiam Mitchell <[email protected]>2025-03-25 17:37:18 -0700
committerLiam Mitchell <[email protected]>2025-03-25 17:46:24 -0700
commitca949ab61d1540d5e6b92c6b5b53d5e3d02d5050 (patch)
treebbf2236822388b2a0548344a7cb040cd880e0d7e /src/zenutil/service.cpp
parentMerge remote-tracking branch 'origin/main' into de/zen-service-command (diff)
downloadzen-ca949ab61d1540d5e6b92c6b5b53d5e3d02d5050.tar.xz
zen-ca949ab61d1540d5e6b92c6b5b53d5e3d02d5050.zip
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.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/zenutil/service.cpp b/src/zenutil/service.cpp
index a2ff93efd..e1c5e17fa 100644
--- a/src/zenutil/service.cpp
+++ b/src/zenutil/service.cpp
@@ -449,6 +449,25 @@ InstallService(std::string_view ServiceName, const ServiceSpec& Spec)
}
}
+ // 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();
+ }
+
CloseServiceHandle(schService);
return {};