aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/config/config.h
blob: 186b80b6bdc7e9693603f9e7ecd96309000ce86a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#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>
#include <filesystem>
#include <string>
#include <vector>

namespace zen::LuaConfig {
struct Options;
}
namespace cxxopts {
class Options;
class ParseResult;
}  // namespace cxxopts
namespace zen {

// Common server configuration

struct ZenStatsConfig
{
	bool		Enabled	   = false;
	std::string StatsdHost = "localhost";
	int			StatsdPort = 8125;
};

struct ZenSentryConfig
{
	bool		Disable	 = false;
	bool		AllowPII = false;  // Allow personally identifiable information in sentry crash reports
	std::string Dsn;
	std::string Environment;
	bool		Debug = false;	// Enable debug mode for Sentry
};

struct HttpClientConfig
{
	std::string Backend = "curl";  // Choice of HTTP client implementation
};

struct ZenServerConfig
{
	HttpClientConfig	  HttpClient;
	HttpServerConfig	  HttpConfig;
	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)
	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;
	TraceOptions TraceCmdLineOptions;
#endif
	std::string MemoryOptions;	// Memory allocation options
	std::string CommandLine;
	std::string EncryptionKey;	// 256 bit AES encryption key
	std::string EncryptionIV;	// 128 bit AES initialization vector

	bool InstallService	  = false;	// Flag used to initiate service install (temporary)
	bool UninstallService = false;	// Flag used to initiate service uninstall (temporary)
};

/** 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);

}  // namespace zen