aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-08-09 21:07:52 +0200
committerStefan Boberg <[email protected]>2021-08-09 21:07:52 +0200
commitc439521bdd3d1bef43fa02917342280e49f85723 (patch)
treeb287c7b1faa74ee5021859f0a30fbf65710d7118
parentAdded ProcessHandle::Reset and added some diagnostics for ProcessHandle::Init... (diff)
downloadzen-c439521bdd3d1bef43fa02917342280e49f85723.tar.xz
zen-c439521bdd3d1bef43fa02917342280e49f85723.zip
Basic implementation of 'down' command
-rw-r--r--zen/cmds/up.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/zen/cmds/up.cpp b/zen/cmds/up.cpp
index 8cc1f8eca..45d2fc7c3 100644
--- a/zen/cmds/up.cpp
+++ b/zen/cmds/up.cpp
@@ -55,5 +55,48 @@ DownCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
{
ZEN_UNUSED(GlobalOptions, argc, argv);
+ int ListenPort = 1337;
+
+ // Discover executing instances
+
+ ZenServerState Instance;
+ Instance.Initialize();
+ ZenServerState::ZenServerEntry* Entry = Instance.Lookup(ListenPort);
+
+ if (!Entry)
+ {
+ spdlog::warn("no zen server to bring down");
+
+ return 0;
+ }
+
+ try
+ {
+ std::filesystem::path ExePath = zen::GetRunningExecutablePath();
+
+ ZenServerEnvironment ServerEnvironment;
+ ServerEnvironment.Initialize(ExePath.parent_path());
+ ZenServerInstance Server(ServerEnvironment);
+ Server.AttachToRunningServer(ListenPort);
+
+ spdlog::info("attached to server on port {}, requesting shutdown", ListenPort);
+
+ Server.Shutdown();
+
+ spdlog::info("shutdown complete");
+
+ return 0;
+ }
+ catch (std::exception& Ex)
+ {
+ spdlog::debug("Exception caught when requesting shutdown: {}", Ex.what());
+ }
+
+ // Since we cannot obtain a handle to the process we are unable to block on the process
+ // handle to determine when the server has shut down. Thus we signal that we would like
+ // a shutdown via the shutdown flag and then
+
+ Entry->SignalShutdownRequest();
+
return 0;
}