aboutsummaryrefslogtreecommitdiff
path: root/zenserver/zenserver.cpp
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-11-25 14:07:24 +0100
committerPer Larsson <[email protected]>2021-11-25 14:07:24 +0100
commit522fbd01d25856c921bb1400b07ae900a0054627 (patch)
treebf649ab7efe41c22661d77196fc52428911cdb57 /zenserver/zenserver.cpp
parentrpc: tactical checkin (diff)
parentAdded support for loading Lua config file from CLI option and merged server/s... (diff)
downloadzen-522fbd01d25856c921bb1400b07ae900a0054627.tar.xz
zen-522fbd01d25856c921bb1400b07ae900a0054627.zip
Merged main.
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 567f1d40b..e9c41d070 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,
@@ -237,9 +237,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
{
@@ -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)
@@ -553,7 +553,7 @@ ZenServer::OnReady()
}
void
-ZenServer::InitializeState(ZenServiceConfig& ServiceConfig)
+ZenServer::InitializeState(const ZenServerOptions& ServerOptions)
{
// Check root manifest to deal with schema versioning
@@ -566,7 +566,7 @@ ZenServer::InitializeState(ZenServiceConfig& ServiceConfig)
if (ManifestData.ErrorCode)
{
- if (ServiceConfig.IsFirstRun)
+ if (ServerOptions.IsFirstRun)
{
ZEN_INFO("Initializing state at '{}'", m_DataRoot);
@@ -650,7 +650,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; };
@@ -659,13 +659,13 @@ ZenServer::InitializeStructuredCache(ZenServiceConfig& ServiceConfig)
m_CacheStore = std::make_unique<ZenCacheStore>(m_Gc, 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)
{
@@ -770,11 +770,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;
@@ -782,8 +778,7 @@ public:
virtual int Run() override;
private:
- ZenServerOptions& m_GlobalOptions;
- ZenServiceConfig& m_ServiceConfig;
+ ZenServerOptions& m_ServerOptions;
zen::LockFile m_LockFile;
};
@@ -802,8 +797,7 @@ ZenWindowsService::Run()
auto _ = zen::MakeGuard([] { sentry_close(); });
#endif
- auto& GlobalOptions = m_GlobalOptions;
- auto& ServiceConfig = m_ServiceConfig;
+ auto& ServerOptions = m_ServerOptions;
try
{
@@ -811,13 +805,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();
};
@@ -831,21 +825,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)
{
@@ -853,34 +841,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
@@ -901,9 +889,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();
}
});
@@ -961,25 +949,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();
@@ -987,7 +974,7 @@ main(int argc, char* argv[])
}
#endif
- ZenWindowsService App(GlobalOptions, ServiceConfig);
+ ZenWindowsService App(ServerOptions);
return App.ServiceMain();
}
catch (std::exception& Ex)