aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-05-09 18:43:15 +0200
committerGitHub <[email protected]>2023-05-09 18:43:15 +0200
commit442d5826bc11f3a37464e2fd90a1d49fa2df0785 (patch)
tree04b641c60bb52c01b5baede65f4b6c0e0bdf9799
parentadd context to MapViewOfFile errors (#282) (diff)
downloadzen-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
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/zenserver/zenserver.cpp25
2 files changed, 26 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3b16398ca..1eca8ede9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
##
+- Feature: zenserver now writes a state_marker file in the root of the data directory. Deleting this file will cause zenserver to exit. This is used to detect if user is deleting the data folder while zenserver is running
- Feature: Disk writes are now blocked early and return an insufficient storage error if free disk space falls below the `--low-diskspace-threshold` value
- Feature: zenserver: Add command line option `--sentry-allow-personal-info` to allow personally identifiable information in sentry reports, disabled by default
- Feature: Age-based GC of oplogs in project store
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