aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil
diff options
context:
space:
mode:
authorLiam Mitchell <[email protected]>2025-08-22 22:29:14 +0000
committerLiam Mitchell <[email protected]>2025-08-22 22:29:14 +0000
commitb905b6d1d94c2a09c268603935991ee3c018c700 (patch)
treeebc8885ebb627b52edbf4ab36427a571916e8d9d /src/zenutil
parentRemove workflow hacks for CI debugging (diff)
downloadzen-b905b6d1d94c2a09c268603935991ee3c018c700.tar.xz
zen-b905b6d1d94c2a09c268603935991ee3c018c700.zip
Move ReportServiceStatus to zenutil and remove extraneous logging
Diffstat (limited to 'src/zenutil')
-rw-r--r--src/zenutil/include/zenutil/service.h2
-rw-r--r--src/zenutil/service.cpp43
-rw-r--r--src/zenutil/xmake.lua8
3 files changed, 53 insertions, 0 deletions
diff --git a/src/zenutil/include/zenutil/service.h b/src/zenutil/include/zenutil/service.h
index 2798bcb1f..a8bb868b3 100644
--- a/src/zenutil/include/zenutil/service.h
+++ b/src/zenutil/include/zenutil/service.h
@@ -53,4 +53,6 @@ std::error_code QueryInstalledService(std::string_view ServiceName, ServiceInfo&
std::error_code StartService(std::string_view ServiceName);
std::error_code StopService(std::string_view ServiceName);
+void ReportServiceStatus(ServiceStatus Status);
+
} // namespace zen
diff --git a/src/zenutil/service.cpp b/src/zenutil/service.cpp
index ab9553cf4..bf2d7d630 100644
--- a/src/zenutil/service.cpp
+++ b/src/zenutil/service.cpp
@@ -25,11 +25,54 @@
# include <unistd.h>
# include <sys/stat.h>
# include <regex>
+
+ZEN_THIRD_PARTY_INCLUDES_START
+# include <systemd/sd-daemon.h>
+ZEN_THIRD_PARTY_INCLUDES_END
+
#endif
namespace zen {
using namespace std::literals;
+void
+ReportServiceStatus(ServiceStatus Status)
+{
+#if ZEN_PLATFORM_WINDOWS
+ switch (Status)
+ {
+ case ServiceStatus::Starting:
+ ReportSvcStatus(SERVICE_START_PENDING, NO_ERROR, 3000);
+ break;
+ case ServiceStatus::Running:
+ ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0);
+ break;
+ case ServiceStatus::Stopping:
+ ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+ break;
+ case ServiceStatus::Stopped:
+ ReportSvcStatus(SERVICE_STOPPED, (DWORD)ApplicationExitCode(), 0);
+ break;
+ default:
+ break;
+ }
+#elif ZEN_PLATFORM_LINUX
+ switch (Status)
+ {
+ case ServiceStatus::Running:
+ sd_notify(0, "READY=1");
+ break;
+ case ServiceStatus::Stopping:
+ sd_notify(0, "STOPPING=1");
+ break;
+ case ServiceStatus::Stopped:
+ sd_notifyf(0, "EXIT_STATUS=%d", ApplicationExitCode());
+ break;
+ }
+#endif
+ (void)Status;
+}
+
namespace {
#if ZEN_PLATFORM_WINDOWS
diff --git a/src/zenutil/xmake.lua b/src/zenutil/xmake.lua
index 3d95651f2..6d87aefcc 100644
--- a/src/zenutil/xmake.lua
+++ b/src/zenutil/xmake.lua
@@ -8,3 +8,11 @@ target('zenutil')
add_includedirs("include", {public=true})
add_deps("zencore", "zenhttp")
add_packages("vcpkg::robin-map", "vcpkg::spdlog")
+
+ if is_plat("linux") then
+ add_includedirs("$(projectdir)/thirdparty/systemd/include")
+ add_linkdirs("$(projectdir)/thirdparty/systemd/lib")
+ add_links("systemd")
+ add_links("cap")
+ end
+