diff options
Diffstat (limited to 'src/zenserver/config')
| -rw-r--r-- | src/zenserver/config/config.cpp | 40 | ||||
| -rw-r--r-- | src/zenserver/config/config.h | 46 |
2 files changed, 65 insertions, 21 deletions
diff --git a/src/zenserver/config/config.cpp b/src/zenserver/config/config.cpp index 2a89fc637..5f53374fc 100644 --- a/src/zenserver/config/config.cpp +++ b/src/zenserver/config/config.cpp @@ -16,6 +16,7 @@ #include <zencore/fmtutils.h> #include <zencore/iobuffer.h> #include <zencore/logging.h> +#include <zencore/session.h> #include <zencore/string.h> #include <zenutil/config/commandlineoptions.h> #include <zenutil/config/environmentoptions.h> @@ -147,6 +148,10 @@ ZenServerConfiguratorBase::AddCommonConfigOptions(LuaConfig::Options& LuaOptions LuaOptions.AddOption("server.clean"sv, ServerOptions.IsCleanStart, "clean"sv); LuaOptions.AddOption("server.security.configpath"sv, ServerOptions.SecurityConfigPath, "security-config-path"sv); + ////// sessions + + LuaOptions.AddOption("sessions.url"sv, ServerOptions.SessionsTargetUrl, "sessions-url"sv); + ////// network LuaOptions.AddOption("network.httpclientbackend"sv, ServerOptions.HttpClient.Backend, "httpclient"sv); @@ -205,6 +210,7 @@ struct ZenServerCmdLineOptions std::string SecurityConfigPath; std::string UnixSocketPath; std::string PortStr; + std::string ParentSessionId; ZenLoggingCmdLineOptions LoggingOptions; @@ -285,10 +291,22 @@ ZenServerCmdLineOptions::AddCliOptions(cxxopts::Options& options, ZenServerConfi .add_option("lifetime", "", "owner-pid", "Specify owning process id", cxxopts::value<int>(ServerOptions.OwnerPid), "<identifier>"); options.add_option("lifetime", "", + "parent-session", + "Specify parent session id used to associate this process with another session", + cxxopts::value<std::string>(ParentSessionId), + "<oid>"); + options.add_option("lifetime", + "", "child-id", "Specify id which can be used to signal parent", cxxopts::value<std::string>(ServerOptions.ChildId), "<identifier>"); + options.add_option("lifetime", + "", + "sessions-url", + "URL of remote zenserver to announce session to", + cxxopts::value<std::string>(ServerOptions.SessionsTargetUrl), + "<url>"); #if ZEN_PLATFORM_WINDOWS options.add_option("lifetime", @@ -519,6 +537,18 @@ ZenServerCmdLineOptions::ApplyOptions(cxxopts::Options& options, ZenServerConfig ServerOptions.BasePort = Port; } + if (!ParentSessionId.empty()) + { + Oid ParsedParentSessionId; + if (!Oid::TryParse(ParentSessionId, ParsedParentSessionId) || ParsedParentSessionId == Oid::Zero) + { + throw OptionParseException(fmt::format("invalid parent session id '{}': expected a 24-character object id", ParentSessionId), + options.help()); + } + ServerOptions.ParentSessionId = ParsedParentSessionId; + SetParentSessionId(ParsedParentSessionId); + } + LoggingOptions.ApplyOptions(ServerOptions.LoggingConfig); #if ZEN_WITH_HTTPSYS @@ -688,6 +718,16 @@ ZenServerConfiguratorBase::Configure(int argc, char* argv[]) { m_ServerOptions.BasePort = ZenServerConfig::kDefaultBasePort; } + + // Resolve sessions target. If neither CLI nor config supplied a value, + // fall back to the ZEN_SESSIONS_URL environment variable. When a remote + // target is configured, session logs flow through SessionsServiceClient + // instead of the in-proc broadcast sink. + if (m_ServerOptions.SessionsTargetUrl.empty()) + { + m_ServerOptions.SessionsTargetUrl = GetEnvVariable("ZEN_SESSIONS_URL").value_or(""); + } + m_ServerOptions.UseInProcSessionLogging = m_ServerOptions.SessionsTargetUrl.empty(); } catch (const OptionParseException& e) { diff --git a/src/zenserver/config/config.h b/src/zenserver/config/config.h index d35a1a8c7..186b80b6b 100644 --- a/src/zenserver/config/config.h +++ b/src/zenserver/config/config.h @@ -4,6 +4,7 @@ #include <zencore/logbase.h> #include <zencore/trace.h> +#include <zencore/uid.h> #include <zencore/zencore.h> #include <zenhttp/httpserver.h> #include <zenutil/config/loggingconfig.h> @@ -50,27 +51,30 @@ struct ZenServerConfig ZenSentryConfig SentryConfig; ZenStatsConfig StatsConfig; ZenLoggingConfig LoggingConfig; - static constexpr int kDefaultBasePort = 8558; - int BasePort = 0; // Service listen port; 0 = auto (resolved per mode) - int OwnerPid = 0; // Parent process id (zero for standalone) - bool IsDebug = false; - bool IsCleanStart = false; // Indicates whether all state should be wiped on startup or not - bool IsPowerCycle = false; // When true, the process shuts down immediately after initialization - bool IsTest = false; - bool Detach = true; // Whether zenserver should detach from existing process group (Mac/Linux) - int CoreLimit = 0; // If set, hardware concurrency queries are capped at this number - int LieCpu = 0; - bool IsDedicated = false; // Indicates a dedicated/shared instance, with larger resource requirements - bool AllowPortProbing = true; // Automatically false if IsDedicated is true - bool ShouldCrash = false; // Option for testing crash handling - bool IsFirstRun = false; - std::filesystem::path ConfigFile; // Path to Lua config file - std::filesystem::path SystemRootDir; // System root directory (used for machine level config) - std::filesystem::path ContentDir; // Root directory for serving frontend content (experimental) - std::filesystem::path DataDir; // Root directory for state (used for testing) - std::filesystem::path BaseSnapshotDir; // Path to server state snapshot (will be copied into data dir on start) - std::string ChildId; // Id assigned by parent process (used for lifetime management) - std::filesystem::path SecurityConfigPath; // Path to a Json security configuration file + static constexpr int kDefaultBasePort = 8558; + int BasePort = 0; // Service listen port; 0 = auto (resolved per mode) + int OwnerPid = 0; // Parent process id (zero for standalone) + Oid ParentSessionId = Oid::Zero; + bool IsDebug = false; + bool IsCleanStart = false; // Indicates whether all state should be wiped on startup or not + bool IsPowerCycle = false; // When true, the process shuts down immediately after initialization + bool IsTest = false; + bool Detach = true; // Whether zenserver should detach from existing process group (Mac/Linux) + int CoreLimit = 0; // If set, hardware concurrency queries are capped at this number + int LieCpu = 0; + bool IsDedicated = false; // Indicates a dedicated/shared instance, with larger resource requirements + bool AllowPortProbing = true; // Automatically false if IsDedicated is true + bool ShouldCrash = false; // Option for testing crash handling + bool IsFirstRun = false; + bool UseInProcSessionLogging = true; // When false, session logs are expected to be forwarded externally. + std::string SessionsTargetUrl; // URL of remote zenserver to announce session to (overrides ZEN_SESSIONS_URL). + std::filesystem::path ConfigFile; // Path to Lua config file + std::filesystem::path SystemRootDir; // System root directory (used for machine level config) + std::filesystem::path ContentDir; // Root directory for serving frontend content (experimental) + std::filesystem::path DataDir; // Root directory for state (used for testing) + std::filesystem::path BaseSnapshotDir; // Path to server state snapshot (will be copied into data dir on start) + std::string ChildId; // Id assigned by parent process (used for lifetime management) + std::filesystem::path SecurityConfigPath; // Path to a Json security configuration file #if ZEN_WITH_TRACE bool HasTraceCommandlineOptions = false; |