aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-10-17 20:35:54 +0200
committerGitHub <[email protected]>2023-10-17 20:35:54 +0200
commitd3e396f7ecd3bcf2df30d2ba203b3548cf6ab5e0 (patch)
tree1ff10db41dc5ba53896ebb7cab1ff840010351ba /src
parentremoved unnecessary vector in ZenCacheMemoryLayer::Drop (diff)
downloadzen-d3e396f7ecd3bcf2df30d2ba203b3548cf6ab5e0.tar.xz
zen-d3e396f7ecd3bcf2df30d2ba203b3548cf6ab5e0.zip
added command line option to start server clean (#481)
when specified with `--clean`, the data directory will be wiped clean at startup
Diffstat (limited to 'src')
-rw-r--r--src/zenserver/config.cpp4
-rw-r--r--src/zenserver/config.h1
-rw-r--r--src/zenserver/main.cpp5
-rw-r--r--src/zenserver/zenserver.cpp68
4 files changed, 48 insertions, 30 deletions
diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp
index 9112222d6..2566d8a3c 100644
--- a/src/zenserver/config.cpp
+++ b/src/zenserver/config.cpp
@@ -773,6 +773,7 @@ ParseConfigFile(const std::filesystem::path& Path,
LuaOptions.AddOption("server.contentdir"sv, ServerOptions.ContentDir, "content-dir"sv);
LuaOptions.AddOption("server.abslog"sv, ServerOptions.AbsLogFile, "abslog"sv);
LuaOptions.AddOption("server.debug"sv, ServerOptions.IsDebug, "debug"sv);
+ LuaOptions.AddOption("server.clean"sv, ServerOptions.IsCleanStart, "clean"sv);
LuaOptions.AddOption("server.noconsole"sv, ServerOptions.NoConsoleOutput, "quiet"sv);
////// objectstore
@@ -925,6 +926,9 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
"Enable dedicated server mode",
cxxopts::value<bool>(ServerOptions.IsDedicated)->default_value("false"));
options.add_options()("d, debug", "Enable debugging", cxxopts::value<bool>(ServerOptions.IsDebug)->default_value("false"));
+ options.add_options()("clean",
+ "Clean out all state at startup",
+ cxxopts::value<bool>(ServerOptions.IsCleanStart)->default_value("false"));
options.add_options()("help", "Show command line help");
options.add_options()("t, test", "Enable test mode", cxxopts::value<bool>(ServerOptions.IsTest)->default_value("false"));
options.add_options()("log-id", "Specify id for adding context to log output", cxxopts::value<std::string>(ServerOptions.LogId));
diff --git a/src/zenserver/config.h b/src/zenserver/config.h
index fecf3fe0c..3006b0e15 100644
--- a/src/zenserver/config.h
+++ b/src/zenserver/config.h
@@ -128,6 +128,7 @@ struct ZenServerOptions
bool InstallService = false; // Flag used to initiate service install (temporary)
bool UninstallService = false; // Flag used to initiate service uninstall (temporary)
bool IsDebug = false;
+ bool IsCleanStart = false; // Indicates whether all state should be wiped on startup or not
bool IsTest = false;
bool IsDedicated = false; // Indicates a dedicated/shared instance, with larger resource requirements
bool ShouldCrash = false; // Option for testing crash handling
diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp
index d57722143..f482e6737 100644
--- a/src/zenserver/main.cpp
+++ b/src/zenserver/main.cpp
@@ -334,6 +334,11 @@ main(int argc, char* argv[])
ZenServerOptions ServerOptions;
ParseCliOptions(argc, argv, ServerOptions);
+ if (ServerOptions.IsCleanStart)
+ {
+ DeleteDirectories(ServerOptions.DataDir);
+ }
+
if (!std::filesystem::exists(ServerOptions.DataDir))
{
ServerOptions.IsFirstRun = true;
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 9d51a581e..60950dbe3 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -308,53 +308,61 @@ ZenServer::InitializeState(const ZenServerOptions& ServerOptions)
bool WipeState = false;
std::string WipeReason = "Unspecified";
+ if (ServerOptions.IsCleanStart)
+ {
+ WipeState = true;
+ WipeReason = "clean start requested";
+ }
+
bool UpdateManifest = false;
std::filesystem::path ManifestPath = m_DataRoot / "root_manifest";
- FileContents ManifestData = ReadFile(ManifestPath);
- if (ManifestData.ErrorCode)
+ if (!WipeState)
{
- if (ServerOptions.IsFirstRun)
- {
- ZEN_INFO("Initializing state at '{}'", m_DataRoot);
+ FileContents ManifestData = ReadFile(ManifestPath);
- UpdateManifest = true;
- }
- else
+ if (ManifestData.ErrorCode)
{
- WipeState = true;
- WipeReason = fmt::format("No manifest present at '{}'", ManifestPath);
- }
- }
- else
- {
- IoBuffer Manifest = ManifestData.Flatten();
-
- if (CbValidateError ValidationResult = ValidateCompactBinary(Manifest, CbValidateMode::All);
- ValidationResult != CbValidateError::None)
- {
- ZEN_WARN("Manifest validation failed: {}, state will be wiped", uint32_t(ValidationResult));
+ if (ServerOptions.IsFirstRun)
+ {
+ ZEN_INFO("Initializing state at '{}'", m_DataRoot);
- WipeState = true;
- WipeReason = fmt::format("Validation of manifest at '{}' failed: {}", ManifestPath, uint32_t(ValidationResult));
+ UpdateManifest = true;
+ }
+ else
+ {
+ WipeState = true;
+ WipeReason = fmt::format("No manifest present at '{}'", ManifestPath);
+ }
}
else
{
- m_RootManifest = LoadCompactBinaryObject(Manifest);
+ IoBuffer Manifest = ManifestData.Flatten();
- const int32_t ManifestVersion = m_RootManifest["schema_version"].AsInt32(0);
-
- if (ManifestVersion != ZEN_CFG_SCHEMA_VERSION)
+ if (CbValidateError ValidationResult = ValidateCompactBinary(Manifest, CbValidateMode::All);
+ ValidationResult != CbValidateError::None)
{
+ ZEN_WARN("Manifest validation failed: {}, state will be wiped", uint32_t(ValidationResult));
+
WipeState = true;
- WipeReason = fmt::format("Manifest schema version: {}, differs from required: {}", ManifestVersion, ZEN_CFG_SCHEMA_VERSION);
+ WipeReason = fmt::format("Validation of manifest at '{}' failed: {}", ManifestPath, uint32_t(ValidationResult));
+ }
+ else
+ {
+ m_RootManifest = LoadCompactBinaryObject(Manifest);
+
+ const int32_t ManifestVersion = m_RootManifest["schema_version"].AsInt32(0);
+
+ if (ManifestVersion != ZEN_CFG_SCHEMA_VERSION)
+ {
+ WipeState = true;
+ WipeReason =
+ fmt::format("Manifest schema version: {}, differs from required: {}", ManifestVersion, ZEN_CFG_SCHEMA_VERSION);
+ }
}
}
}
- // Release any open handles so we can overwrite the manifest
- ManifestData = {};
-
// Handle any state wipe
if (WipeState)