diff options
Diffstat (limited to 'zenserver/zenserver.cpp')
| -rw-r--r-- | zenserver/zenserver.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index c55d3497e..646b6cf5c 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -12,6 +12,7 @@ #include <zenstore/cas.h> #include <zenstore/cidstore.h> +#include <exception> #include <fmt/format.h> #include <mimalloc-new-delete.h> #include <mimalloc.h> @@ -78,6 +79,15 @@ public: } } + // Initialize/check mutex based on base port + + std::string MutexName = "zen_{}"_format(BasePort); + + if (zen::NamedMutex::Exists(MutexName) || (m_ServerMutex.Create(MutexName) == false)) + { + throw std::exception("Failed to create mutex '{}' - is another instance already running?"_format(MutexName).c_str()); + } + // Ok so now we're configured, let's kick things off zen::CasStoreConfiguration Config; @@ -231,6 +241,7 @@ private: asio::io_context m_IoContext; asio::steady_timer m_PidCheckTimer{m_IoContext}; zen::Process m_Process; + zen::NamedMutex m_ServerMutex; zen::HttpServer m_Http; std::unique_ptr<zen::CasStore> m_CasStore{zen::CreateCasStore()}; @@ -277,6 +288,9 @@ main(int argc, char* argv[]) Server.SetTestMode(GlobalOptions.IsTest); Server.Initialize(ServiceConfig, GlobalOptions.BasePort, GlobalOptions.OwnerPid); + // If we have a parent process, establish the mechanisms we need + // to be able to communicate with the parent + if (!GlobalOptions.ChildId.empty()) { zen::ExtendableStringBuilder<64> ShutdownEventName; @@ -287,6 +301,7 @@ main(int argc, char* argv[]) ParentEvent.Set(); ShutdownThread.reset(new std::thread{[&] { + spdlog::info("shutdown monitor thread waiting for shutdown signal '{}'", ShutdownEventName); ShutdownEvent->Wait(); spdlog::info("shutdown signal received"); Server.RequestExit(0); |