#include "command_registry.hpp" #include "config.hpp" #include "utils/utils.hpp" #include "utils/directories.hpp" #include "shared_commands.hpp" #include "servers.hpp" #include "services.hpp" #include "servers.hpp" #include "utils/output.hpp" namespace dropshell { int start_handler(const CommandContext &ctx); static std::vector start_name_list = {"start", "start-service"}; // Static registration struct StartCommandRegister { StartCommandRegister() { CommandRegistry::instance().register_command({start_name_list, start_handler, shared_commands::std_autocomplete_allowall, false, // hidden true, // requires_config true, // requires_install 1, // min_args (after command) 2, // max_args (after command) "start SERVER SERVICE|all", "Start a service or all services on a server.", R"( start SERVER SERVICE Starts the given service on the given server. start SERVER all Starts all services on the given server. Note: This command will not create any data or configuration. It will simply start the service on the remote server. Stop the service with stop, or uninstall with uninstall. )"}); } } start_command_register; bool start_service(const std::string &server, const std::string &service) { ServerConfig server_env(server); if (!server_env.is_valid()) { error << "Server " << server << " is not valid" << std::endl; return false; } // run the start script. bool started = server_env.run_remote_template_command(service, "start", {}, false, {}); if (started) { info << "Service " << service << " on server " << server << " started." << std::endl; return true; } error << "Failed to start service " << service << " on server " << server << std::endl; return false; } int start_handler(const CommandContext &ctx) { if (ctx.args.size() < 2) { error << "Server name and service name are both required" << std::endl; return 1; } std::string server = safearg(ctx.args, 0); std::string service = safearg(ctx.args, 1); if (service == "all") { // install all services on the server maketitle("Stopping all services on " + server); bool okay = true; std::vector services = get_server_services_info(server); for (const auto &service : services) okay &= start_service(server, service.service_name); return okay ? 0 : 1; } // start the specific service. return start_service(server, service) ? 0 : 1; } } // namespace dropshell