aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/main.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-03-14 09:48:15 +0100
committerDan Engelbrecht <[email protected]>2025-03-14 09:48:15 +0100
commit18aeb8856dc168336955f0d2778cdc74c64a680f (patch)
tree83932b76bb01d1a9e9b473bf5bbc36cfca1c2b5b /src/zenserver/main.cpp
parentMerge remote-tracking branch 'origin/main' into de/zen-service-command (diff)
parentMerge pull request #288 from ue-foundation/lm/zen-service-command (diff)
downloadzen-18aeb8856dc168336955f0d2778cdc74c64a680f.tar.xz
zen-18aeb8856dc168336955f0d2778cdc74c64a680f.zip
Merge remote-tracking branch 'origin/de/zen-service-command' into de/zen-service-command
Diffstat (limited to 'src/zenserver/main.cpp')
-rw-r--r--src/zenserver/main.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp
index f35010866..9ae54bdf1 100644
--- a/src/zenserver/main.cpp
+++ b/src/zenserver/main.cpp
@@ -23,6 +23,8 @@
#include <zencore/memory/memorytrace.h>
#include <zencore/memory/newdelete.h>
+#include <zenutil/service.h>
+
#include "config.h"
#include "diag/logging.h"
#include "sentryintegration.h"
@@ -32,6 +34,10 @@
# include "windows/service.h"
#endif
+#if ZEN_PLATFORM_LINUX
+# include <systemd/sd-daemon.h>
+#endif
+
//////////////////////////////////////////////////////////////////////////
// We don't have any doctest code in this file but this is needed to bring
// in some shared code into the executable
@@ -88,6 +94,43 @@ ZenEntryPoint::ZenEntryPoint(ZenServerOptions& ServerOptions) : m_ServerOptions(
{
}
+void
+ReportServiceStatus(ServiceStatus Status)
+{
+#if ZEN_PLATFORM_WINDOWS
+ switch (Status)
+ {
+ case ServiceStatus::Starting:
+ ReportSvcStatus(SERVICE_START_PENDING, NO_ERROR, 3000);
+ break;
+ case ServiceStatus::Running:
+ ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0);
+ break;
+ case ServiceStatus::Stopping:
+ ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+ break;
+ case ServiceStatus::Stopped:
+ ReportSvcStatus(SERVICE_STOPPED, (DWORD)ApplicationExitCode(), 0);
+ break;
+ default:
+ break;
+ }
+#elif ZEN_PLATFORM_LINUX
+ switch (Status)
+ {
+ case ServiceStatus::Running:
+ sd_notify(0, "READY=1");
+ break;
+ case ServiceStatus::Stopping:
+ sd_notify(0, "STOPPING=1");
+ break;
+ case ServiceStatus::Stopped:
+ sd_notifyf(0, "EXIT_STATUS=%d", ApplicationExitCode());
+ break;
+ }
+#endif
+}
+
int
ZenEntryPoint::Run()
{
@@ -281,6 +324,8 @@ ZenEntryPoint::Run()
}});
auto CleanupShutdown = MakeGuard([&ShutdownEvent, &ShutdownThread] {
+ ReportServiceStatus(ServiceStatus::Stopping);
+
if (ShutdownEvent)
{
ShutdownEvent->Set();
@@ -302,6 +347,8 @@ ZenEntryPoint::Run()
NamedEvent ParentEvent{m_ServerOptions.ChildId};
ParentEvent.Set();
}
+
+ ReportServiceStatus(ServiceStatus::Running);
});
Server.Run();
@@ -327,6 +374,8 @@ ZenEntryPoint::Run()
ShutdownServerLogging();
+ ReportServiceStatus(ServiceStatus::Stopped);
+
return ApplicationExitCode();
}
@@ -396,6 +445,10 @@ main(int argc, char* argv[])
signal(SIGINT, utils::SignalCallbackHandler);
signal(SIGTERM, utils::SignalCallbackHandler);
+#if ZEN_PLATFORM_LINUX
+ IgnoreChildSignals();
+#endif
+
try
{
ZenServerOptions ServerOptions;