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