aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/main.cpp
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/main.cpp
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/main.cpp')
-rw-r--r--src/zenserver/main.cpp109
1 files changed, 62 insertions, 47 deletions
diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp
index 3119b37c6..43ddc14c9 100644
--- a/src/zenserver/main.cpp
+++ b/src/zenserver/main.cpp
@@ -63,7 +63,7 @@ template<class T>
class ZenWindowsService : public WindowsService
{
public:
- ZenWindowsService(ZenStorageServerOptions& ServerOptions) : m_EntryPoint(ServerOptions) {}
+ ZenWindowsService(typename T::Config& ServerOptions) : m_EntryPoint(ServerOptions) {}
ZenWindowsService(const ZenWindowsService&) = delete;
ZenWindowsService& operator=(const ZenWindowsService&) = delete;
@@ -80,60 +80,31 @@ private:
//////////////////////////////////////////////////////////////////////////
-#if ZEN_WITH_TESTS
-int
-test_main(int argc, char** argv)
-{
- zen::logging::InitializeLogging();
- zen::logging::SetLogLevel(zen::logging::level::Debug);
-
- zen::MaximizeOpenFileCount();
-
- return ZEN_RUN_TESTS(argc, argv);
-}
-#endif
+namespace zen {
+template<class Main>
int
-main(int argc, char* argv[])
+AppMain(int argc, char* argv[])
{
- using namespace zen;
-
- if (argc >= 2)
- {
- if (argv[1] == "test"sv)
- {
-#if ZEN_WITH_TESTS
- return test_main(argc, argv);
-#else
- fprintf(stderr, "test option not available in release mode!\n");
- exit(5);
-#endif
- }
- }
-
- signal(SIGINT, utils::SignalCallbackHandler);
- signal(SIGTERM, utils::SignalCallbackHandler);
-
-#if ZEN_PLATFORM_LINUX
- IgnoreChildSignals();
-#endif
+ using namespace std::literals;
try
{
- ZenStorageServerOptions ServerOptions;
+ typename Main::Config ServerOptions;
- {
#if ZEN_WITH_TRACE
- TraceInit("zenserver");
- ServerOptions.HasTraceCommandlineOptions = GetTraceOptionsFromCommandline(ServerOptions.TraceOptions);
- if (ServerOptions.HasTraceCommandlineOptions)
- {
- TraceConfigure(ServerOptions.TraceOptions);
- }
-#endif // ZEN_WITH_TRACE
+ TraceInit("zenserver");
+ ServerOptions.HasTraceCommandlineOptions = GetTraceOptionsFromCommandline(/* out */ ServerOptions.TraceOptions);
+ if (ServerOptions.HasTraceCommandlineOptions)
+ {
+ TraceConfigure(ServerOptions.TraceOptions);
}
+#endif // ZEN_WITH_TRACE
- ParseCliOptions(argc, argv, ServerOptions);
+ {
+ typename Main::Configurator Configurator(ServerOptions);
+ Configurator.Configure(argc, argv);
+ }
if (ServerOptions.Detach)
{
@@ -194,7 +165,7 @@ main(int argc, char* argv[])
std::exit(0);
}
- ZenWindowsService<ZenStorageServerMain> App(ServerOptions);
+ ZenWindowsService<Main> App(ServerOptions);
return App.ServiceMain();
#else
if (ServerOptions.InstallService || ServerOptions.UninstallService)
@@ -202,7 +173,7 @@ main(int argc, char* argv[])
throw std::runtime_error("Service mode is not supported on this platform");
}
- ZenStorageServerMain App(ServerOptions);
+ Main App(ServerOptions);
return App.Run();
#endif
}
@@ -224,3 +195,47 @@ main(int argc, char* argv[])
return 1;
}
}
+} // namespace zen
+
+//////////////////////////////////////////////////////////////////////////
+
+#if ZEN_WITH_TESTS
+int
+test_main(int argc, char** argv)
+{
+ zen::logging::InitializeLogging();
+ zen::logging::SetLogLevel(zen::logging::level::Debug);
+
+ zen::MaximizeOpenFileCount();
+
+ return ZEN_RUN_TESTS(argc, argv);
+}
+#endif
+
+int
+main(int argc, char* argv[])
+{
+ using namespace zen;
+
+ if (argc >= 2)
+ {
+ if (argv[1] == "test"sv)
+ {
+#if ZEN_WITH_TESTS
+ return test_main(argc, argv);
+#else
+ fprintf(stderr, "test option not available in release mode!\n");
+ exit(5);
+#endif
+ }
+ }
+
+ signal(SIGINT, utils::SignalCallbackHandler);
+ signal(SIGTERM, utils::SignalCallbackHandler);
+
+#if ZEN_PLATFORM_LINUX
+ IgnoreChildSignals();
+#endif
+
+ return AppMain<ZenStorageServerMain>(argc, argv);
+}