// Copyright Epic Games, Inc. All Rights Reserved. #include "up.h" #include #include #include #include namespace zen { UpCommand::UpCommand() { } UpCommand::~UpCommand() = default; int UpCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) { ZEN_UNUSED(GlobalOptions, argc, argv); std::filesystem::path ExePath = zen::GetRunningExecutablePath(); ZenServerEnvironment ServerEnvironment; ServerEnvironment.Initialize(ExePath.parent_path()); ZenServerInstance Server(ServerEnvironment); Server.SpawnServer(); int Timeout = 10000; if (!Server.WaitUntilReady(Timeout)) { ZEN_ERROR("zen server launch failed (timed out)"); } else { ZEN_INFO("zen server up"); } return 0; } ////////////////////////////////////////////////////////////////////////// DownCommand::DownCommand() { } DownCommand::~DownCommand() = default; int 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) { ZEN_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); ZEN_INFO("attached to server on port {}, requesting shutdown", ListenPort); Server.Shutdown(); ZEN_INFO("shutdown complete"); return 0; } catch (std::exception& Ex) { ZEN_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; } } // namespace zen