diff options
| author | Dan Engelbrecht <[email protected]> | 2023-05-09 18:43:15 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-09 18:43:15 +0200 |
| commit | 442d5826bc11f3a37464e2fd90a1d49fa2df0785 (patch) | |
| tree | 04b641c60bb52c01b5baede65f4b6c0e0bdf9799 /src/zenserver/zenserver.cpp | |
| parent | add context to MapViewOfFile errors (#282) (diff) | |
| download | zen-442d5826bc11f3a37464e2fd90a1d49fa2df0785.tar.xz zen-442d5826bc11f3a37464e2fd90a1d49fa2df0785.zip | |
monitor if a state-maker file still exists, and if not error out and exit (#283)
* monitor if a state-maker file still exists, and if not error out and exit
Diffstat (limited to 'src/zenserver/zenserver.cpp')
| -rw-r--r-- | src/zenserver/zenserver.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp index c6ec4b82b..2469c5c85 100644 --- a/src/zenserver/zenserver.cpp +++ b/src/zenserver/zenserver.cpp @@ -512,6 +512,24 @@ public: EnsureIoRunner(); } + void EnqueueStateMarkerTimer() + { + m_StateMakerTimer.expires_after(std::chrono::seconds(5)); + m_StateMakerTimer.async_wait([this](const asio::error_code&) { CheckStateMarker(); }); + EnsureIoRunner(); + } + + void CheckStateMarker() + { + std::filesystem::path StateMarkerPath = m_DataRoot / "state_marker"; + if (!std::filesystem::exists(StateMarkerPath)) + { + ZEN_ERROR("state marker at {} has been deleted, exiting", StateMarkerPath); + RequestExit(0); + } + EnqueueStateMarkerTimer(); + } + void CheckOwnerPid() { // Pick up any new "owner" processes @@ -595,6 +613,7 @@ private: std::thread m_IoRunner; asio::io_context m_IoContext; asio::steady_timer m_PidCheckTimer{m_IoContext}; + asio::steady_timer m_StateMakerTimer{m_IoContext}; zen::ProcessMonitor m_ProcessMonitor; zen::NamedMutex m_ServerMutex; @@ -758,6 +777,12 @@ ZenServer::InitializeState(const ZenServerOptions& ServerOptions) WriteFile(ManifestPath, m_RootManifest.GetBuffer().AsIoBuffer()); } + { + std::filesystem::path StateMarkerPath = m_DataRoot / "state_marker"; + static const std::string_view StateMarkerContent = "deleting this file will cause " ZEN_APP_NAME " to exit"sv; + WriteFile(StateMarkerPath, IoBuffer(IoBuffer::Wrap, StateMarkerContent.data(), StateMarkerContent.size())); + EnqueueStateMarkerTimer(); + } } void |