diff options
| author | Liam Mitchell <[email protected]> | 2025-03-04 18:13:14 -0800 |
|---|---|---|
| committer | Liam Mitchell <[email protected]> | 2025-03-04 18:13:14 -0800 |
| commit | 8857b1551e719478f50d914c34a1e63782045b86 (patch) | |
| tree | 5cfa05a47757c503a427a7a6c406ea25cf550d19 /src/zenserver | |
| parent | Implementation of service commands for Linux. (diff) | |
| download | zen-8857b1551e719478f50d914c34a1e63782045b86.tar.xz zen-8857b1551e719478f50d914c34a1e63782045b86.zip | |
Initial implementation of service status reporting
Diffstat (limited to 'src/zenserver')
| -rw-r--r-- | src/zenserver/main.cpp | 45 | ||||
| -rw-r--r-- | src/zenserver/windows/service.cpp | 8 | ||||
| -rw-r--r-- | src/zenserver/windows/service.h | 4 |
3 files changed, 49 insertions, 8 deletions
diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index 41e8d782c..636e7f6c1 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" @@ -88,6 +90,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 +320,8 @@ ZenEntryPoint::Run() }}); auto CleanupShutdown = MakeGuard([&ShutdownEvent, &ShutdownThread] { + ReportServiceStatus(ServiceStatus::Stopping); + if (ShutdownEvent) { ShutdownEvent->Set(); @@ -302,6 +343,8 @@ ZenEntryPoint::Run() NamedEvent ParentEvent{m_ServerOptions.ChildId}; ParentEvent.Set(); } + + ReportServiceStatus(ServiceStatus::Running); }); Server.Run(); @@ -327,6 +370,8 @@ ZenEntryPoint::Run() ShutdownServerLogging(); + ReportServiceStatus(ServiceStatus::Stopped); + return ApplicationExitCode(); } diff --git a/src/zenserver/windows/service.cpp b/src/zenserver/windows/service.cpp index cb87df1f6..4be5e6205 100644 --- a/src/zenserver/windows/service.cpp +++ b/src/zenserver/windows/service.cpp @@ -21,7 +21,6 @@ HANDLE ghSvcStopEvent = NULL; void SvcInstall(void); -void ReportSvcStatus(DWORD, DWORD, DWORD); void SvcReportEvent(LPTSTR); WindowsService::WindowsService() @@ -222,14 +221,7 @@ WindowsService::SvcMain() return 1; } - // Report running status when initialization is complete. - - ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0); - int ReturnCode = Run(); - - ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0); - return ReturnCode; } diff --git a/src/zenserver/windows/service.h b/src/zenserver/windows/service.h index 7c9610983..ca0270a36 100644 --- a/src/zenserver/windows/service.h +++ b/src/zenserver/windows/service.h @@ -2,6 +2,8 @@ #pragma once +#include <zencore/windows.h> + class WindowsService { public: @@ -18,3 +20,5 @@ public: int SvcMain(); static void __stdcall SvcCtrlHandler(unsigned long); }; + +VOID ReportSvcStatus(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint); |