diff options
| author | Stefan Boberg <[email protected]> | 2021-09-17 23:18:20 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-17 23:18:48 +0200 |
| commit | 0ee89539ead8631b02953ddf601770aefa557edb (patch) | |
| tree | ef2e09d747bb3d7497507362bda560b905d478d6 /zenserver/zenserver.cpp | |
| parent | Added IsInteractiveSession() query to help identify if the process is running... (diff) | |
| download | zen-0ee89539ead8631b02953ddf601770aefa557edb.tar.xz zen-0ee89539ead8631b02953ddf601770aefa557edb.zip | |
zenserver can now run as a Windows service. We'll still need to improve how data files are found as the current defaults are relative to the user directory which ends up being in the Windows folder when running as the local system user
Diffstat (limited to 'zenserver/zenserver.cpp')
| -rw-r--r-- | zenserver/zenserver.cpp | 79 |
1 files changed, 56 insertions, 23 deletions
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index 83580b288..ea4a2915e 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -316,7 +316,9 @@ public: __debugbreak(); } - m_Http->Run(m_TestMode); + const bool IsInteractiveMode = zen::IsInteractiveSession() && !m_TestMode; + + m_Http->Run(IsInteractiveMode); ZEN_INFO(ZEN_APP_NAME " exiting"); @@ -436,33 +438,29 @@ private: } // namespace zen -int -main(int argc, char* argv[]) +class ZenWindowsService : public WindowsService { - using namespace zen; - - mi_version(); - - ZenServerOptions GlobalOptions; - ZenServiceConfig ServiceConfig; - ParseGlobalCliOptions(argc, argv, GlobalOptions, ServiceConfig); - InitializeLogging(GlobalOptions); - -#if ZEN_PLATFORM_WINDOWS - if (GlobalOptions.InstallService) +public: + ZenWindowsService(ZenServerOptions& GlobalOptions, ZenServiceConfig& ServiceConfig) + : m_GlobalOptions(GlobalOptions) + , m_ServiceConfig(ServiceConfig) { - SvcInstall(); - - std::exit(0); } - if (GlobalOptions.UninstallService) - { - SvcDelete(); + ZenWindowsService(const ZenWindowsService&) = delete; + ZenWindowsService& operator=(const ZenWindowsService&) = delete; - std::exit(0); - } -#endif + virtual int Run() override; + +private: + ZenServerOptions& m_GlobalOptions; + ZenServiceConfig& m_ServiceConfig; +}; + +int +ZenWindowsService::Run() +{ + using namespace zen; #if USE_SENTRY // Initialize sentry.io client @@ -474,6 +472,9 @@ main(int argc, char* argv[]) auto _ = zen::MakeGuard([] { sentry_close(); }); #endif + auto& GlobalOptions = m_GlobalOptions; + auto& ServiceConfig = m_ServiceConfig; + try { // Prototype config system, we'll see how this pans out @@ -559,3 +560,35 @@ main(int argc, char* argv[]) return 0; } + +int +main(int argc, char* argv[]) +{ + using namespace zen; + + mi_version(); + + ZenServerOptions GlobalOptions; + ZenServiceConfig ServiceConfig; + ParseGlobalCliOptions(argc, argv, GlobalOptions, ServiceConfig); + InitializeLogging(GlobalOptions); + +#if ZEN_PLATFORM_WINDOWS + if (GlobalOptions.InstallService) + { + WindowsService::Install(); + + std::exit(0); + } + + if (GlobalOptions.UninstallService) + { + WindowsService::Delete(); + + std::exit(0); + } +#endif + + ZenWindowsService App(GlobalOptions, ServiceConfig); + return App.ServiceMain(); +} |