This commit is contained in:
parent
891f0d023f
commit
27f86e95e7
11
source/src/autogen/version.hpp
Normal file
11
source/src/autogen/version.hpp
Normal file
@ -0,0 +1,11 @@
|
||||
// version.hpp (dummy for linter/IntelliSense)
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace dropshell {
|
||||
extern const std::string VERSION;
|
||||
extern const std::string RELEASE_DATE;
|
||||
extern const std::string AUTHOR;
|
||||
extern const std::string LICENSE;
|
||||
}
|
@ -57,7 +57,10 @@ void help_autocomplete(const CommandContext& ctx) {
|
||||
void show_command(const std::string& cmd) {
|
||||
const auto& cmd_info = CommandRegistry::instance().find_command(cmd);
|
||||
if (!cmd_info)
|
||||
{
|
||||
std::cout << "Unknown command: " << cmd << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << " ";
|
||||
print_left_aligned(cmd_info->help_usage, 30);
|
||||
@ -119,6 +122,13 @@ int help_handler(const CommandContext& ctx) {
|
||||
{
|
||||
// show more!
|
||||
show_command("list");
|
||||
std::cout << std::endl;
|
||||
show_command("install");
|
||||
show_command("uninstall");
|
||||
show_command("nuke");
|
||||
std::cout << std::endl;
|
||||
show_command("start");
|
||||
show_command("stop");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -121,6 +121,7 @@ namespace dropshell
|
||||
|
||||
// Run install script
|
||||
{
|
||||
std::cout << "Running " << service_info.template_name << " install script on " << server << "..." << std::endl;
|
||||
server_env.run_remote_template_command(service, "install", {}, silent, {});
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,16 @@ struct NukeCommandRegister {
|
||||
"Nuke a service on a server. Destroys everything, both local and remote!",
|
||||
// heredoc
|
||||
R"(
|
||||
Nuke a service on a server. Destroys everything, both local and remote!
|
||||
Nuke a service.
|
||||
|
||||
Examples:
|
||||
nuke SERVER SERVICE nuke the given service on the given server.
|
||||
nuke SERVER all nuke all services on the given server.
|
||||
|
||||
Note: This command is destructive and will destroy all data and all configuration,
|
||||
both on the dropshell host and on the remote server.
|
||||
|
||||
Use with caution!
|
||||
)"
|
||||
});
|
||||
}
|
||||
|
91
source/src/commands/start.cpp
Normal file
91
source/src/commands/start.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
#include "command_registry.hpp"
|
||||
#include "config.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include "utils/directories.hpp"
|
||||
#include "shared_commands.hpp"
|
||||
#include "server_env_manager.hpp"
|
||||
#include "services.hpp"
|
||||
#include "servers.hpp"
|
||||
|
||||
namespace dropshell
|
||||
{
|
||||
|
||||
int start_handler(const CommandContext &ctx);
|
||||
|
||||
static std::vector<std::string> 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)
|
||||
{
|
||||
server_env_manager server_env(server);
|
||||
if (!server_env.is_valid())
|
||||
{
|
||||
std::cerr << "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)
|
||||
{
|
||||
std::cout << "Service " << service << " on server " << server << " started." << std::endl;
|
||||
return true;
|
||||
}
|
||||
std::cerr << "Error: Failed to start service " << service << " on server " << server << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int start_handler(const CommandContext &ctx)
|
||||
{
|
||||
if (ctx.args.size() < 2)
|
||||
{
|
||||
std::cerr << "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<LocalServiceInfo> 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
|
91
source/src/commands/stop.cpp
Normal file
91
source/src/commands/stop.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
#include "command_registry.hpp"
|
||||
#include "config.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include "utils/directories.hpp"
|
||||
#include "shared_commands.hpp"
|
||||
#include "server_env_manager.hpp"
|
||||
#include "services.hpp"
|
||||
#include "servers.hpp"
|
||||
|
||||
namespace dropshell
|
||||
{
|
||||
|
||||
int stop_handler(const CommandContext &ctx);
|
||||
|
||||
static std::vector<std::string> stop_name_list = {"stop", "stop-service"};
|
||||
|
||||
// Static registration
|
||||
struct StopCommandRegister
|
||||
{
|
||||
StopCommandRegister()
|
||||
{
|
||||
CommandRegistry::instance().register_command({stop_name_list,
|
||||
stop_handler,
|
||||
shared_commands::std_autocomplete_allowall,
|
||||
false, // hidden
|
||||
true, // requires_config
|
||||
true, // requires_install
|
||||
1, // min_args (after command)
|
||||
2, // max_args (after command)
|
||||
"stop SERVER SERVICE|all",
|
||||
"Stop a service or all services on a server.",
|
||||
R"(
|
||||
|
||||
stop SERVER SERVICE Stops the given service on the given server.
|
||||
stop SERVER all Stops all services on the given server.
|
||||
|
||||
Note: This command will not destroy any data or configuration.
|
||||
It will simply stop the service on the remote server.
|
||||
Restart the service with start, or update and start it with install.
|
||||
)"});
|
||||
}
|
||||
} stop_command_register;
|
||||
|
||||
bool stop_service(const std::string &server, const std::string &service)
|
||||
{
|
||||
server_env_manager server_env(server);
|
||||
if (!server_env.is_valid())
|
||||
{
|
||||
std::cerr << "Error: Server " << server << " is not valid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// run the stop script.
|
||||
bool stopped = server_env.run_remote_template_command(service, "stop", {}, false, {});
|
||||
|
||||
if (stopped)
|
||||
{
|
||||
std::cout << "Service " << service << " on server " << server << " stopped." << std::endl;
|
||||
return true;
|
||||
}
|
||||
std::cerr << "Error: Failed to stop service " << service << " on server " << server << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int stop_handler(const CommandContext &ctx)
|
||||
{
|
||||
if (ctx.args.size() < 2)
|
||||
{
|
||||
std::cerr << "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<LocalServiceInfo> services = get_server_services_info(server);
|
||||
for (const auto &service : services)
|
||||
okay &= stop_service(server, service.service_name);
|
||||
return okay ? 0 : 1;
|
||||
}
|
||||
|
||||
// stop the specific service.
|
||||
return stop_service(server, service) ? 0 : 1;
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
@ -31,16 +31,16 @@ namespace dropshell
|
||||
"Uninstall a service on a server. Does not remove configuration or user data.",
|
||||
// heredoc
|
||||
R"(
|
||||
Uninstall a service on a server. Does not remove configuration or user data.
|
||||
uninstall SERVER SERVICE uninstall the given service on the given server.
|
||||
uninstall SERVER all uninstall all services on the given server.
|
||||
Uninstall a service, leaving all configuration and data intact.
|
||||
|
||||
uninstall SERVER SERVICE Uninstall the given service on the given server.
|
||||
uninstall SERVER all Uninstall all services on the given server.
|
||||
|
||||
Update and reinstall the service with install, or delete all configuration and data with nuke.
|
||||
)"});
|
||||
}
|
||||
} uninstall_command_register;
|
||||
|
||||
|
||||
|
||||
|
||||
bool uninstall_service(const std::string &server, const std::string &service, bool silent = false)
|
||||
{
|
||||
if (!silent)
|
||||
@ -81,7 +81,6 @@ namespace dropshell
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int uninstall_handler(const CommandContext &ctx)
|
||||
{
|
||||
if (ctx.args.size() < 1)
|
||||
@ -109,5 +108,4 @@ namespace dropshell
|
||||
return uninstall_service(server, service) ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
} // namespace dropshell
|
Loading…
x
Reference in New Issue
Block a user