From 531c59032bbc46bc1f7284859fa8ff8c8b5ede61 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 15 Jan 2025 09:30:12 +0100 Subject: systemd unit file, incomplete --- src/zenserver/main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/zenserver/main.cpp') diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index d5419d342..6bf369ca4 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -91,6 +91,7 @@ ZenEntryPoint::ZenEntryPoint(ZenServerOptions& ServerOptions) : m_ServerOptions( int ZenEntryPoint::Run() { + ZEN_INFO("ZenEntryPoint::Run()"); zen::SetCurrentThreadName("main"); #if ZEN_USE_SENTRY @@ -107,8 +108,11 @@ ZenEntryPoint::Run() try { // Mutual exclusion and synchronization + ZEN_INFO("ZenServerState ServerState"); ZenServerState ServerState; + ZEN_INFO("ServerState.Initialize()"); ServerState.Initialize(); + ZEN_INFO("ServerState.Sweep()"); ServerState.Sweep(); uint32_t AttachSponsorProcessRetriesLeft = 3; @@ -173,6 +177,8 @@ ZenEntryPoint::Run() } } + ZEN_INFO("Preparing lock file"); + std::error_code Ec; std::filesystem::path LockFilePath = m_ServerOptions.DataDir / ".lock"; @@ -186,6 +192,7 @@ ZenEntryPoint::Run() .ExecutablePath = GetRunningExecutablePath()}); }; + ZEN_INFO("m_LockFile.Create"); m_LockFile.Create(LockFilePath, MakeLockData(false), Ec); if (Ec) @@ -201,6 +208,7 @@ ZenEntryPoint::Run() } } + ZEN_INFO("InitializeServerLogging"); InitializeServerLogging(m_ServerOptions); ZEN_INFO("Command line: {}", m_ServerOptions.CommandLine); @@ -303,6 +311,11 @@ ZenEntryPoint::Run() ZEN_CRITICAL("Caught assert exception in main for process {}: {}", zen::GetCurrentProcessId(), AssertEx.FullDescription()); RequestApplicationExit(1); } + catch (const std::system_error& e) + { + ZEN_CRITICAL("Caught system error exception in main for process {}: {} ({})", zen::GetCurrentProcessId(), e.what(), e.code().value()); + RequestApplicationExit(1); + } catch (const std::exception& e) { ZEN_CRITICAL("Caught exception in main for process {}: {}", zen::GetCurrentProcessId(), e.what()); -- cgit v1.2.3 From 53531a6b22dbb7b690db43964172e9d0f670c3c8 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 15 Jan 2025 10:17:02 +0100 Subject: clang format --- src/zenserver/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/zenserver/main.cpp') diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index 6bf369ca4..f35010866 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -313,7 +313,10 @@ ZenEntryPoint::Run() } catch (const std::system_error& e) { - ZEN_CRITICAL("Caught system error exception in main for process {}: {} ({})", zen::GetCurrentProcessId(), e.what(), e.code().value()); + ZEN_CRITICAL("Caught system error exception in main for process {}: {} ({})", + zen::GetCurrentProcessId(), + e.what(), + e.code().value()); RequestApplicationExit(1); } catch (const std::exception& e) -- cgit v1.2.3 From c49b0a053c5e28de1afa83600ebffd383766e38a Mon Sep 17 00:00:00 2001 From: Liam Mitchell Date: Thu, 27 Feb 2025 02:16:10 +0000 Subject: Implementation of service commands for Linux. --- src/zenserver/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/zenserver/main.cpp') diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index f35010866..41e8d782c 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -396,6 +396,10 @@ main(int argc, char* argv[]) signal(SIGINT, utils::SignalCallbackHandler); signal(SIGTERM, utils::SignalCallbackHandler); +#if ZEN_PLATFORM_LINUX + IgnoreChildSignals(); +#endif + try { ZenServerOptions ServerOptions; -- cgit v1.2.3 From 8857b1551e719478f50d914c34a1e63782045b86 Mon Sep 17 00:00:00 2001 From: Liam Mitchell Date: Tue, 4 Mar 2025 18:13:14 -0800 Subject: Initial implementation of service status reporting --- src/zenserver/main.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/zenserver/main.cpp') 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 #include +#include + #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(); } -- cgit v1.2.3 From 2b823aa2088587575f62784c150af75c2535618b Mon Sep 17 00:00:00 2001 From: Liam Mitchell Date: Wed, 5 Mar 2025 02:33:21 +0000 Subject: Update Linux service type and add libsystemd dependency --- src/zenserver/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/zenserver/main.cpp') diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index 636e7f6c1..9ae54bdf1 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -34,6 +34,10 @@ # include "windows/service.h" #endif +#if ZEN_PLATFORM_LINUX +# include +#endif + ////////////////////////////////////////////////////////////////////////// // We don't have any doctest code in this file but this is needed to bring // in some shared code into the executable -- cgit v1.2.3 From 157f21e39e0226228833965d5a1d125fce5d30b2 Mon Sep 17 00:00:00 2001 From: Liam Mitchell Date: Wed, 20 Aug 2025 23:35:02 +0000 Subject: Add pre-built systemd library and remove vcpkg dependency --- src/zenserver/main.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/zenserver/main.cpp') diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index 6bd098da9..f8f25877b 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -35,7 +35,9 @@ #endif #if ZEN_PLATFORM_LINUX +ZEN_THIRD_PARTY_INCLUDES_START # include +ZEN_THIRD_PARTY_INCLUDES_END #endif ////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From c2bac0c4103e1af53a5f6ab74e5567f5a5191b93 Mon Sep 17 00:00:00 2001 From: Liam Mitchell Date: Thu, 21 Aug 2025 23:30:03 +0000 Subject: Ignore unused variable warnings on platforms where ReportServiceStatus is unimplemented --- src/zenserver/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/zenserver/main.cpp') diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index f8f25877b..76e022017 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -131,6 +131,7 @@ ReportServiceStatus(ServiceStatus Status) break; } #endif + (void)Status; } int -- cgit v1.2.3 From b905b6d1d94c2a09c268603935991ee3c018c700 Mon Sep 17 00:00:00 2001 From: Liam Mitchell Date: Fri, 22 Aug 2025 22:29:14 +0000 Subject: Move ReportServiceStatus to zenutil and remove extraneous logging --- src/zenserver/main.cpp | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) (limited to 'src/zenserver/main.cpp') diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index 4ea4ee87e..e3c88f8bb 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -34,12 +34,6 @@ # include "windows/service.h" #endif -#if ZEN_PLATFORM_LINUX -ZEN_THIRD_PARTY_INCLUDES_START -# include -ZEN_THIRD_PARTY_INCLUDES_END -#endif - ////////////////////////////////////////////////////////////////////////// // We don't have any doctest code in this file but this is needed to bring // in some shared code into the executable @@ -96,43 +90,6 @@ 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 - (void)Status; -} int ZenEntryPoint::Run() @@ -160,11 +117,8 @@ ZenEntryPoint::Run() try { // Mutual exclusion and synchronization - ZEN_INFO("ZenServerState ServerState"); ZenServerState ServerState; - ZEN_INFO("ServerState.Initialize()"); ServerState.Initialize(); - ZEN_INFO("ServerState.Sweep()"); ServerState.Sweep(); auto NotifyReady = [&] { @@ -238,8 +192,6 @@ ZenEntryPoint::Run() } } - ZEN_INFO("Preparing lock file"); - std::error_code Ec; std::filesystem::path LockFilePath = m_ServerOptions.DataDir / ".lock"; @@ -253,7 +205,6 @@ ZenEntryPoint::Run() .ExecutablePath = GetRunningExecutablePath()}); }; - ZEN_INFO("m_LockFile.Create"); m_LockFile.Create(LockFilePath, MakeLockData(false), Ec); if (Ec) @@ -269,7 +220,6 @@ ZenEntryPoint::Run() } } - ZEN_INFO("InitializeServerLogging"); InitializeServerLogging(m_ServerOptions); ZEN_INFO("Command line: {}", m_ServerOptions.CommandLine); -- cgit v1.2.3 From 623f5bbd39e24a8a26203c02bafc3800d74d1db0 Mon Sep 17 00:00:00 2001 From: Liam Mitchell Date: Fri, 22 Aug 2025 15:51:32 -0700 Subject: Move windows service utilities to zenutil and fix clang-format errors --- src/zenserver/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/zenserver/main.cpp') diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index e3c88f8bb..6b22e1a0f 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -31,7 +31,7 @@ #if ZEN_PLATFORM_WINDOWS # include -# include "windows/service.h" +# include #endif ////////////////////////////////////////////////////////////////////////// @@ -90,7 +90,6 @@ ZenEntryPoint::ZenEntryPoint(ZenServerOptions& ServerOptions) : m_ServerOptions( { } - int ZenEntryPoint::Run() { -- cgit v1.2.3