From c956e958e0a386f24e6865ad62ee4fe640f93b18 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 17 Apr 2024 12:42:01 +0200 Subject: zen startup hardening (#49) - Feature: `zen up` command improvements - --`port` allows you to specify a base port when starting an instance - --`base-dir` allows you to specify a base directory for the zenserver executable if it is not located next to the zen.exe executable - Feature: `zen down` - --`port` allows you to specify a base port when shutting down an instance - --`base-dir` allows you to specify a base directory for the zenserver executable if it is not located next to the zen.exe executable - --`force` if regular shutdown fails it tries to find a running zenserver.exe process and terminate it - If it fails to attach to the running server it now waits for it to exit when setting the RequestExit shared memory flag - Improvement: zenserver now checks the RequestExit flag in the shared memory and exist gracefully if it is set - Improvement: When adding a sponsor process to a running zenserver instance, we wait for it to be picked up from the shared memory section to determine success/fail --- src/zenserver/zenserver.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/zenserver/zenserver.cpp') diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp index e6e451952..86dbc9617 100644 --- a/src/zenserver/zenserver.cpp +++ b/src/zenserver/zenserver.cpp @@ -475,6 +475,8 @@ ZenServer::InitializeState(const ZenServerOptions& ServerOptions) EnqueueStateMarkerTimer(); } + + EnqueueStateExitFlagTimer(); } void @@ -804,6 +806,14 @@ ZenServer::EnqueueSigIntTimer() EnsureIoRunner(); } +void +ZenServer::EnqueueStateExitFlagTimer() +{ + m_SigIntTimer.expires_after(std::chrono::milliseconds(500)); + m_SigIntTimer.async_wait([this](const asio::error_code&) { CheckStateExitFlag(); }); + EnsureIoRunner(); +} + void ZenServer::EnqueueStatsReportingTimer() { @@ -858,6 +868,17 @@ ZenServer::CheckSigInt() EnqueueSigIntTimer(); } +void +ZenServer::CheckStateExitFlag() +{ + if (m_ServerEntry && m_ServerEntry->IsShutdownRequested()) + { + RequestExit(0); + return; + } + EnqueueStateExitFlagTimer(); +} + bool ZenServer::UpdateProcessMonitor() { -- cgit v1.2.3