diff options
| author | Martin Ridgers <[email protected]> | 2021-11-29 09:18:03 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2021-11-29 09:18:03 +0100 |
| commit | 91aa9708bd42960405019148d39b57dda0155367 (patch) | |
| tree | b4ed6d1273e53cbe95e2ec20c37373f629947592 /zenserver/zenserver.cpp | |
| parent | Added a simple NamedMutex test (diff) | |
| parent | Merge pull request #28 from EpicGames/non-elevated-asio (diff) | |
| download | zen-91aa9708bd42960405019148d39b57dda0155367.tar.xz zen-91aa9708bd42960405019148d39b57dda0155367.zip | |
Merged main
Diffstat (limited to 'zenserver/zenserver.cpp')
| -rw-r--r-- | zenserver/zenserver.cpp | 97 |
1 files changed, 44 insertions, 53 deletions
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index 3caf37084..ff0c01f4f 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -155,12 +155,12 @@ namespace utils { class ZenServer : public IHttpStatusProvider { public: - void Initialize(ZenServiceConfig& ServiceConfig, const ZenServerOptions& ServerOptions, ZenServerState::ZenServerEntry* ServerEntry) + void Initialize(const ZenServerOptions& ServerOptions, ZenServerState::ZenServerEntry* ServerEntry) { using namespace fmt::literals; m_ServerEntry = ServerEntry; - m_DebugOptionForcedCrash = ServiceConfig.ShouldCrash; + m_DebugOptionForcedCrash = ServerOptions.ShouldCrash; const int ParentPid = ServerOptions.OwnerPid; if (ParentPid) @@ -192,7 +192,7 @@ public: throw std::runtime_error("Failed to create mutex '{}' - is another instance already running?"_format(MutexName).c_str()); } - InitializeState(ServiceConfig); + InitializeState(ServerOptions); m_HealthService.SetHealthInfo({.DataRoot = m_DataRoot, .AbsLogPath = ServerOptions.AbsLogFile, @@ -237,9 +237,9 @@ public: m_HttpFunctionService = std::make_unique<zen::HttpFunctionService>(*m_CasStore, *m_CidStore, ApplySandboxDir); #endif // ZEN_WITH_COMPUTE_SERVICES - if (ServiceConfig.StructuredCacheEnabled) + if (ServerOptions.StructuredCacheEnabled) { - InitializeStructuredCache(ServiceConfig); + InitializeStructuredCache(ServerOptions); } else { @@ -247,7 +247,7 @@ public: } #if ZEN_ENABLE_MESH - if (ServiceConfig.MeshEnabled) + if (ServerOptions.MeshEnabled) { StartMesh(BasePort); } @@ -293,8 +293,8 @@ public: } } - void InitializeState(ZenServiceConfig& ServiceConfig); - void InitializeStructuredCache(ZenServiceConfig& ServiceConfig); + void InitializeState(const ZenServerOptions& ServerOptions); + void InitializeStructuredCache(const ZenServerOptions& ServerOptions); #if ZEN_ENABLE_MESH void StartMesh(int BasePort) @@ -539,7 +539,7 @@ ZenServer::OnReady() } void -ZenServer::InitializeState(ZenServiceConfig& ServiceConfig) +ZenServer::InitializeState(const ZenServerOptions& ServerOptions) { // Check root manifest to deal with schema versioning @@ -552,7 +552,7 @@ ZenServer::InitializeState(ZenServiceConfig& ServiceConfig) if (ManifestData.ErrorCode) { - if (ServiceConfig.IsFirstRun) + if (ServerOptions.IsFirstRun) { ZEN_INFO("Initializing state at '{}'", m_DataRoot); @@ -633,7 +633,7 @@ ZenServer::InitializeState(ZenServiceConfig& ServiceConfig) } void -ZenServer::InitializeStructuredCache(ZenServiceConfig& ServiceConfig) +ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions) { using namespace std::literals; auto ValueOrDefault = [](std::string_view Value, std::string_view Default) { return Value.empty() ? Default : Value; }; @@ -642,13 +642,13 @@ ZenServer::InitializeStructuredCache(ZenServiceConfig& ServiceConfig) m_CacheStore = std::make_unique<ZenCacheStore>(m_DataRoot / "cache"); std::unique_ptr<zen::UpstreamCache> UpstreamCache; - if (ServiceConfig.UpstreamCacheConfig.CachePolicy != UpstreamCachePolicy::Disabled) + if (ServerOptions.UpstreamCacheConfig.CachePolicy != UpstreamCachePolicy::Disabled) { - const ZenUpstreamCacheConfig& UpstreamConfig = ServiceConfig.UpstreamCacheConfig; + const ZenUpstreamCacheConfig& UpstreamConfig = ServerOptions.UpstreamCacheConfig; zen::UpstreamCacheOptions UpstreamOptions; - UpstreamOptions.ReadUpstream = (uint8_t(ServiceConfig.UpstreamCacheConfig.CachePolicy) & uint8_t(UpstreamCachePolicy::Read)) != 0; - UpstreamOptions.WriteUpstream = (uint8_t(ServiceConfig.UpstreamCacheConfig.CachePolicy) & uint8_t(UpstreamCachePolicy::Write)) != 0; + UpstreamOptions.ReadUpstream = (uint8_t(ServerOptions.UpstreamCacheConfig.CachePolicy) & uint8_t(UpstreamCachePolicy::Read)) != 0; + UpstreamOptions.WriteUpstream = (uint8_t(ServerOptions.UpstreamCacheConfig.CachePolicy) & uint8_t(UpstreamCachePolicy::Write)) != 0; if (UpstreamConfig.UpstreamThreadCount < 32) { @@ -757,14 +757,13 @@ ZenServer::InitializeStructuredCache(ZenServiceConfig& ServiceConfig) class ZenEntryPoint { public: - ZenEntryPoint(ZenServerOptions& GlobalOptions, ZenServiceConfig& ServiceConfig); + ZenEntryPoint(ZenServerOptions& ServerOptions); ZenEntryPoint(const ZenEntryPoint&) = delete; ZenEntryPoint& operator = (const ZenEntryPoint&) = delete; int Run(); private: - ZenServerOptions& m_GlobalOptions; - ZenServiceConfig& m_ServiceConfig; + ZenServerOptions& m_ServerOptions; zen::LockFile m_LockFile; }; @@ -788,8 +787,7 @@ ZenEntryPoint::Run() auto _ = zen::MakeGuard([] { sentry_close(); }); #endif - auto& GlobalOptions = m_GlobalOptions; - auto& ServiceConfig = m_ServiceConfig; + auto& ServerOptions = m_ServerOptions; try { @@ -797,13 +795,13 @@ ZenEntryPoint::Run() std::error_code Ec; - std::filesystem::path LockFilePath = GlobalOptions.DataDir / ".lock"; + std::filesystem::path LockFilePath = ServerOptions.DataDir / ".lock"; bool IsReady = false; auto MakeLockData = [&] { CbObjectWriter Cbo; - Cbo << "pid" << zen::GetCurrentProcessId() << "data" << PathToUtf8(GlobalOptions.DataDir) << "port" << GlobalOptions.BasePort << "session_id" + Cbo << "pid" << zen::GetCurrentProcessId() << "data" << PathToUtf8(ServerOptions.DataDir) << "port" << ServerOptions.BasePort << "session_id" << GetSessionId() << "ready" << IsReady; return Cbo.Save(); }; @@ -817,21 +815,15 @@ ZenEntryPoint::Run() std::exit(99); } - InitializeLogging(GlobalOptions); + InitializeLogging(ServerOptions); - // Prototype config system, we'll see how this pans out - // - // TODO: we need to report any parse errors here - - ParseServiceConfig(GlobalOptions.DataDir, /* out */ ServiceConfig); - - ZEN_INFO(ZEN_APP_NAME " - starting on port {}, build '{}'", GlobalOptions.BasePort, BUILD_VERSION); + ZEN_INFO(ZEN_APP_NAME " - starting on port {}, build '{}'", ServerOptions.BasePort, BUILD_VERSION); ZenServerState ServerState; ServerState.Initialize(); ServerState.Sweep(); - ZenServerState::ZenServerEntry* Entry = ServerState.Lookup(GlobalOptions.BasePort); + ZenServerState::ZenServerEntry* Entry = ServerState.Lookup(ServerOptions.BasePort); if (Entry) { @@ -839,34 +831,34 @@ ZenEntryPoint::Run() ZEN_WARN("Looks like there is already a process listening to this port (pid: {})", Entry->Pid); - if (GlobalOptions.OwnerPid) + if (ServerOptions.OwnerPid) { - Entry->AddSponsorProcess(GlobalOptions.OwnerPid); + Entry->AddSponsorProcess(ServerOptions.OwnerPid); std::exit(0); } } - Entry = ServerState.Register(GlobalOptions.BasePort); + Entry = ServerState.Register(ServerOptions.BasePort); - if (GlobalOptions.OwnerPid) + if (ServerOptions.OwnerPid) { - Entry->AddSponsorProcess(GlobalOptions.OwnerPid); + Entry->AddSponsorProcess(ServerOptions.OwnerPid); } std::unique_ptr<std::thread> ShutdownThread; std::unique_ptr<zen::NamedEvent> ShutdownEvent; zen::ExtendableStringBuilder<64> ShutdownEventName; - ShutdownEventName << "Zen_" << GlobalOptions.BasePort << "_Shutdown"; + ShutdownEventName << "Zen_" << ServerOptions.BasePort << "_Shutdown"; ShutdownEvent.reset(new zen::NamedEvent{ShutdownEventName}); ZenServer Server; - Server.SetDataRoot(GlobalOptions.DataDir); - Server.SetContentRoot(GlobalOptions.ContentDir); - Server.SetTestMode(GlobalOptions.IsTest); - Server.SetDedicatedMode(GlobalOptions.IsDedicated); - Server.Initialize(ServiceConfig, GlobalOptions, Entry); + Server.SetDataRoot(ServerOptions.DataDir); + Server.SetContentRoot(ServerOptions.ContentDir); + Server.SetTestMode(ServerOptions.IsTest); + Server.SetDedicatedMode(ServerOptions.IsDedicated); + Server.Initialize(ServerOptions, Entry); // Monitor shutdown signals @@ -891,9 +883,9 @@ ZenEntryPoint::Run() m_LockFile.Update(MakeLockData(), Ec); - if (!GlobalOptions.ChildId.empty()) + if (!ServerOptions.ChildId.empty()) { - zen::NamedEvent ParentEvent{GlobalOptions.ChildId}; + zen::NamedEvent ParentEvent{ServerOptions.ChildId}; ParentEvent.Set(); } }); @@ -984,14 +976,13 @@ main(int argc, char* argv[]) try { - ZenServerOptions GlobalOptions; - ZenServiceConfig ServiceConfig; - ParseGlobalCliOptions(argc, argv, GlobalOptions, ServiceConfig); + ZenServerOptions ServerOptions; + ParseCliOptions(argc, argv, ServerOptions); - if (!std::filesystem::exists(GlobalOptions.DataDir)) + if (!std::filesystem::exists(ServerOptions.DataDir)) { - ServiceConfig.IsFirstRun = true; - std::filesystem::create_directories(GlobalOptions.DataDir); + ServerOptions.IsFirstRun = true; + std::filesystem::create_directories(ServerOptions.DataDir); } #if ZEN_WITH_TRACE @@ -1006,21 +997,21 @@ main(int argc, char* argv[]) #endif // ZEN_WITH_TRACE #if ZEN_PLATFORM_WINDOWS - if (GlobalOptions.InstallService) + if (ServerOptions.InstallService) { WindowsService::Install(); std::exit(0); } - if (GlobalOptions.UninstallService) + if (ServerOptions.UninstallService) { WindowsService::Delete(); std::exit(0); } - ZenWindowsService App(GlobalOptions, ServiceConfig); + ZenWindowsService App(ServerOptions); return App.ServiceMain(); #else if (GlobalOptions.InstallService || GlobalOptions.UninstallService) |