aboutsummaryrefslogtreecommitdiff
path: root/zenserver/zenserver.cpp
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-11-25 10:49:23 +0100
committerPer Larsson <[email protected]>2021-11-25 10:49:23 +0100
commitc4968d460be263ff5761a1ebd7f79b5e77dc91d2 (patch)
treea4cb578e3a58466b71c2de2af935b3934ac130ea /zenserver/zenserver.cpp
parentMerge branch 'main' of https://github.com/EpicGames/zen (diff)
downloadzen-c4968d460be263ff5761a1ebd7f79b5e77dc91d2.tar.xz
zen-c4968d460be263ff5761a1ebd7f79b5e77dc91d2.zip
Added support for loading Lua config file from CLI option and merged server/service config.
Diffstat (limited to 'zenserver/zenserver.cpp')
-rw-r--r--zenserver/zenserver.cpp101
1 files changed, 44 insertions, 57 deletions
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp
index b36d84c22..b1989e1bc 100644
--- a/zenserver/zenserver.cpp
+++ b/zenserver/zenserver.cpp
@@ -151,12 +151,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)
@@ -188,7 +188,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,
@@ -231,9 +231,9 @@ public:
zen::CreateDirectories(ApplySandboxDir);
m_HttpFunctionService = std::make_unique<zen::HttpFunctionService>(*m_CasStore, *m_CidStore, ApplySandboxDir);
- if (ServiceConfig.StructuredCacheEnabled)
+ if (ServerOptions.StructuredCacheEnabled)
{
- InitializeStructuredCache(ServiceConfig);
+ InitializeStructuredCache(ServerOptions);
}
else
{
@@ -241,7 +241,7 @@ public:
}
#if ZEN_ENABLE_MESH
- if (ServiceConfig.MeshEnabled)
+ if (ServerOptions.MeshEnabled)
{
StartMesh(BasePort);
}
@@ -285,8 +285,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)
@@ -529,7 +529,7 @@ ZenServer::OnReady()
}
void
-ZenServer::InitializeState(ZenServiceConfig& ServiceConfig)
+ZenServer::InitializeState(const ZenServerOptions& ServerOptions)
{
// Check root manifest to deal with schema versioning
@@ -542,7 +542,7 @@ ZenServer::InitializeState(ZenServiceConfig& ServiceConfig)
if (ManifestData.ErrorCode)
{
- if (ServiceConfig.IsFirstRun)
+ if (ServerOptions.IsFirstRun)
{
ZEN_INFO("Initializing state at '{}'", m_DataRoot);
@@ -623,7 +623,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; };
@@ -632,13 +632,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)
{
@@ -747,11 +747,7 @@ ZenServer::InitializeStructuredCache(ZenServiceConfig& ServiceConfig)
class ZenWindowsService : public WindowsService
{
public:
- ZenWindowsService(ZenServerOptions& GlobalOptions, ZenServiceConfig& ServiceConfig)
- : m_GlobalOptions(GlobalOptions)
- , m_ServiceConfig(ServiceConfig)
- {
- }
+ ZenWindowsService(ZenServerOptions& ServerOptions) : m_ServerOptions(ServerOptions) {}
ZenWindowsService(const ZenWindowsService&) = delete;
ZenWindowsService& operator=(const ZenWindowsService&) = delete;
@@ -759,8 +755,7 @@ public:
virtual int Run() override;
private:
- ZenServerOptions& m_GlobalOptions;
- ZenServiceConfig& m_ServiceConfig;
+ ZenServerOptions& m_ServerOptions;
zen::LockFile m_LockFile;
};
@@ -779,8 +774,7 @@ ZenWindowsService::Run()
auto _ = zen::MakeGuard([] { sentry_close(); });
#endif
- auto& GlobalOptions = m_GlobalOptions;
- auto& ServiceConfig = m_ServiceConfig;
+ auto& ServerOptions = m_ServerOptions;
try
{
@@ -788,13 +782,13 @@ ZenWindowsService::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" << _getpid() << "data" << ToUtf8(GlobalOptions.DataDir) << "port" << GlobalOptions.BasePort << "session_id"
+ Cbo << "pid" << _getpid() << "data" << ToUtf8(ServerOptions.DataDir) << "port" << ServerOptions.BasePort << "session_id"
<< GetSessionId() << "ready" << IsReady;
return Cbo.Save();
};
@@ -808,21 +802,15 @@ ZenWindowsService::Run()
std::exit(99);
}
- InitializeLogging(GlobalOptions);
-
- // Prototype config system, we'll see how this pans out
- //
- // TODO: we need to report any parse errors here
-
- ParseServiceConfig(GlobalOptions.DataDir, /* out */ ServiceConfig);
+ InitializeLogging(ServerOptions);
- 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)
{
@@ -830,34 +818,34 @@ ZenWindowsService::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
@@ -878,9 +866,9 @@ ZenWindowsService::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();
}
});
@@ -938,25 +926,24 @@ 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_PLATFORM_WINDOWS
- if (GlobalOptions.InstallService)
+ if (ServerOptions.InstallService)
{
WindowsService::Install();
std::exit(0);
}
- if (GlobalOptions.UninstallService)
+ if (ServerOptions.UninstallService)
{
WindowsService::Delete();
@@ -964,7 +951,7 @@ main(int argc, char* argv[])
}
#endif
- ZenWindowsService App(GlobalOptions, ServiceConfig);
+ ZenWindowsService App(ServerOptions);
return App.ServiceMain();
}
catch (std::exception& Ex)