From 52b4944e191e0737421cffb3020c96b6c3c03915 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Wed, 17 Dec 2025 08:36:02 +0100 Subject: [PATCH 1/3] registry: add hidden experimental status file argument Signed-off-by: Daniel Edwards --- Utilities/SilKitRegistry/Registry.cpp | 75 +++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/Utilities/SilKitRegistry/Registry.cpp b/Utilities/SilKitRegistry/Registry.cpp index 01c5bde9a..d376df8e2 100644 --- a/Utilities/SilKitRegistry/Registry.cpp +++ b/Utilities/SilKitRegistry/Registry.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "silkit/config/IParticipantConfiguration.hpp" #include "silkit/services/logging/string_utils.hpp" @@ -307,6 +308,69 @@ auto StartRegistry(std::shared_ptr co return result; } +class StatusFile +{ + std::optional path; + +public: + StatusFile() = default; + + explicit StatusFile(const std::filesystem::path& path) : path{Resolve(path)} + { + Write("starting"); + } + + ~StatusFile() + { + Write("stopped"); + + if (path.has_value()) + { + try + { + std::filesystem::remove(path.value()); + } + catch (const std::exception& exception) + { + std::cerr << "Error: Failed to remove status file " << path.value() << ": " << exception.what() << std::endl; + } + } + } + + void Write(const std::string_view content) + { + if (!path.has_value()) + { + return; + } + + try + { + std::ofstream file{path.value(), std::ios::out | std::ios::trunc | std::ios::binary}; + file << content; + file.flush(); + file.close(); + } + catch (const std::exception & exception) + { + std::cerr << "Error: Failed to write status file " << path.value() << ": " << exception.what() << std::endl; + } + } + + static auto Resolve(const std::filesystem::path& path) -> std::optional + { + try + { + return std::filesystem::absolute(path); + } + catch (const std::exception& exception) + { + std::cerr << "Error: Failed to resolve status file path " << path << ": " << exception.what() << std::endl; + return std::nullopt; + } + } +}; + } // namespace int main(int argc, char** argv) @@ -345,6 +409,12 @@ int main(int argc, char** argv) "not set, the process runs infinitely.", CliParser::Hidden); + commandlineParser.Add( + "x-status-file", "", "", "[--x-status-file ]", + "--x-status-file : The registry process will write the current status ('starting' or 'running') as the " + "entire content of the file. This option is ignored if the registry is run as a Windows service.", + CliParser::Hidden); + if (SilKitRegistry::HasWindowsServiceSupport()) { commandlineParser.Add("windows-service", "W", "[--windows-service]", @@ -414,6 +484,9 @@ int main(int argc, char** argv) const auto useSignalHandler{commandlineParser.Get("use-signal-handler").Value()}; auto enableDashboard{commandlineParser.Get("dashboard-uri").HasValue()}; + const auto argStatusFile{commandlineParser.Get("x-status-file").Value()}; + auto statusFile = argStatusFile.empty() ? StatusFile{} : StatusFile{argStatusFile}; + if (commandlineParser.Get("enable-dashboard").Value()) { if (enableDashboard) @@ -490,6 +563,8 @@ int main(int argc, char** argv) { const auto registry = callStartRegistry(); + statusFile.Write("running"); + std::cout << "Press Ctrl-C to terminate..." << std::endl; std::promise signalPromise; From a307b510356c5c48663d8456dd9d03ab1d367744 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 21 Apr 2026 13:39:43 +0200 Subject: [PATCH 2/3] fixup! registry: add hidden experimental status file argument Signed-off-by: Daniel Edwards --- Utilities/SilKitRegistry/Registry.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Utilities/SilKitRegistry/Registry.cpp b/Utilities/SilKitRegistry/Registry.cpp index d376df8e2..9c3387b1f 100644 --- a/Utilities/SilKitRegistry/Registry.cpp +++ b/Utilities/SilKitRegistry/Registry.cpp @@ -483,9 +483,7 @@ int main(int argc, char** argv) auto dashboardUri{commandlineParser.Get("dashboard-uri").Value()}; const auto useSignalHandler{commandlineParser.Get("use-signal-handler").Value()}; auto enableDashboard{commandlineParser.Get("dashboard-uri").HasValue()}; - const auto argStatusFile{commandlineParser.Get("x-status-file").Value()}; - auto statusFile = argStatusFile.empty() ? StatusFile{} : StatusFile{argStatusFile}; if (commandlineParser.Get("enable-dashboard").Value()) { @@ -504,6 +502,9 @@ int main(int argc, char** argv) bool windowsService{SilKitRegistry::HasWindowsServiceSupport() && commandlineParser.Get("windows-service").Value()}; + // Use the status file only if the path isn't empty and the registry is not running as a Windows service. + auto statusFile = argStatusFile.empty() || windowsService ? StatusFile{} : StatusFile{argStatusFile}; + if (!isValidLogLevel(logLevel)) { std::cerr << "Error: Argument '' must be one of " From b4269dedb9f1e67649f2d989471b3d804b9b2c18 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Thu, 7 May 2026 11:15:33 +0200 Subject: [PATCH 3/3] fixup! registry: add hidden experimental status file argument Signed-off-by: Daniel Edwards --- Utilities/SilKitRegistry/Registry.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Utilities/SilKitRegistry/Registry.cpp b/Utilities/SilKitRegistry/Registry.cpp index 9c3387b1f..db7ef9fb5 100644 --- a/Utilities/SilKitRegistry/Registry.cpp +++ b/Utilities/SilKitRegistry/Registry.cpp @@ -411,8 +411,9 @@ int main(int argc, char** argv) commandlineParser.Add( "x-status-file", "", "", "[--x-status-file ]", - "--x-status-file : The registry process will write the current status ('starting' or 'running') as the " - "entire content of the file. This option is ignored if the registry is run as a Windows service.", + "--x-status-file : The registry process will write the current status ('starting', 'running', or " + "'stopped') as the entire content of the file. This option is ignored if the registry is run as a Windows " + "service.", CliParser::Hidden); if (SilKitRegistry::HasWindowsServiceSupport())