aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/config/config.h
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-10-15 09:51:52 +0200
committerGitHub Enterprise <[email protected]>2025-10-15 09:51:52 +0200
commite747932819e2a64a1396cfbc3422a9b61c9470dc (patch)
tree1db1d13cf7fe873d71128a7879d269174f8eaf16 /src/zenserver/config/config.h
parentrefactor builds cmd part3 (#573) (diff)
downloadzen-e747932819e2a64a1396cfbc3422a9b61c9470dc.tar.xz
zen-e747932819e2a64a1396cfbc3422a9b61c9470dc.zip
restructured zenserver configuration (#575)
this breaks out the configuration logic to allow multiple applications to share common configuration and initialization logic whilst customizing chosen aspects of the process
Diffstat (limited to 'src/zenserver/config/config.h')
-rw-r--r--src/zenserver/config/config.h54
1 files changed, 40 insertions, 14 deletions
diff --git a/src/zenserver/config/config.h b/src/zenserver/config/config.h
index 8471ee89b..467f26ee7 100644
--- a/src/zenserver/config/config.h
+++ b/src/zenserver/config/config.h
@@ -19,7 +19,7 @@ class ParseResult;
} // namespace cxxopts
namespace zen {
-struct ZenStorageServerOptions;
+// Common server configuration
struct ZenStatsConfig
{
@@ -37,10 +37,11 @@ struct ZenSentryConfig
bool Debug = false; // Enable debug mode for Sentry
};
-struct ZenServerOptions
+struct ZenServerConfig
{
HttpServerConfig HttpServerConfig;
ZenSentryConfig SentryConfig;
+ ZenStatsConfig StatsConfig;
int BasePort = 8558; // Service listen port (used for both UDP and TCP)
int OwnerPid = 0; // Parent process id (zero for standalone)
bool IsDebug = false;
@@ -54,13 +55,14 @@ struct ZenServerOptions
bool IsDedicated = false; // Indicates a dedicated/shared instance, with larger resource requirements
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 AbsLogFile; // Absolute path to main log file
- std::string ChildId; // Id assigned by parent process (used for lifetime management)
- std::string LogId; // Id for tagging log output
+ 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 AbsLogFile; // Absolute path to main log file
+ 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::string LogId; // Id for tagging log output
std::string Loggers[zen::logging::level::LogLevelCount];
#if ZEN_WITH_TRACE
bool HasTraceCommandlineOptions = false;
@@ -71,17 +73,41 @@ struct ZenServerOptions
std::string EncryptionKey; // 256 bit AES encryption key
std::string EncryptionIV; // 128 bit AES initialization vector
- ZenStatsConfig StatsConfig;
-
bool InstallService = false; // Flag used to initiate service install (temporary)
bool UninstallService = false; // Flag used to initiate service uninstall (temporary)
};
-void ParseCliOptions(int argc, char* argv[], ZenStorageServerOptions& ServerOptions);
+/** Configuration helper - pulls together command line, environment variables
+ and config file parsing logic. Designed to allow a set of common configuration
+ options to be shared among a set of applications which may or may not all be
+ linked into a single executable.
+
+ The virtual functions are used by derived classes to extend and customize the
+ configuration process.
+ */
+struct ZenServerConfiguratorBase
+{
+ ZenServerConfiguratorBase(ZenServerConfig& BaseServerOptions);
+ virtual ~ZenServerConfiguratorBase();
+
+ void Configure(int argc, char* argv[]);
+
+protected:
+ virtual void AddCliOptions(cxxopts::Options& options) = 0;
+ virtual void ApplyOptions(cxxopts::Options& options) = 0;
+ virtual void ValidateOptions() = 0;
+ virtual void AddConfigOptions(LuaConfig::Options& Options) = 0;
+ virtual void OnConfigFileParsed(LuaConfig::Options& LuaOptions) = 0;
+
+private:
+ ZenServerConfig& m_ServerOptions;
+
+ void ParseEnvVariables(const cxxopts::ParseResult& CmdLineResult);
+ void ParseConfigFile(const std::filesystem::path& Path, const cxxopts::ParseResult& CmdLineResult, std::string_view OutputConfigFile);
+ void AddCommonConfigOptions(LuaConfig::Options& LuaOptions);
+};
void EmitCentralManifest(const std::filesystem::path& SystemRoot, Oid Identifier, CbObject Manifest, std::filesystem::path ManifestPath);
std::vector<CbObject> ReadAllCentralManifests(const std::filesystem::path& SystemRoot);
-void AddServerConfigOptions(LuaConfig::Options& LuaOptions, ZenServerOptions& ServerOptions);
-
} // namespace zen