.
This commit is contained in:
74
src/main.cpp
74
src/main.cpp
@ -40,14 +40,17 @@ bool print_help() {
|
||||
std::cout << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Service commands: (if no service is specified, all services for the server are affected)" << std::endl;
|
||||
std::cout << " install SERVER [SERVICE] Install/reinstall/update service(s). Non-destructive." << std::endl;
|
||||
std::cout << " list [SERVER] [SERVICE] List status/details of all servers/server/service." << std::endl;
|
||||
std::cout << " edit [SERVER] [SERVICE] Edit the configuration of dropshell/server/service." << std::endl;
|
||||
std::cout << " COMMAND SERVER [SERVICE] Run a command on service(s)." << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Standard commands: install, uninstall, backup, restore, start, stop" << std::endl;
|
||||
std::cout << " install SERVER [SERVICE] Install/reinstall/update service(s). Safe/non-destructive." << std::endl;
|
||||
std::cout << " uninstall SERVER [SERVICE] Uninstalls the service on the remote server. Leaves data intact." << std::endl;
|
||||
std::cout << " nuke SERVER SERVICE Nuke the service on the remote server, deleting all remote data." << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << " ssh SERVER [SERVICE] Launch an interactive shell on a server or service" << std::endl;
|
||||
std::cout << " COMMAND SERVER [SERVICE] Run a command on service(s), e.g." << std::endl;
|
||||
std::cout << " backup, restore, start, stop, logs" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << " ssh SERVER SERVICE Launch an interactive shell on a server or service" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "Creation commands: (apply to the first local config directory)"<<std::endl;
|
||||
std::cout << " create-template TEMPLATE" << std::endl;
|
||||
@ -116,18 +119,17 @@ int main(int argc, char* argv[]) {
|
||||
if (gConfig().is_config_set())
|
||||
gTemplateManager().load_sources();
|
||||
|
||||
if (argc < 2) {
|
||||
print_help();
|
||||
return 0;
|
||||
}
|
||||
if (argc < 2)
|
||||
return print_help() ? 0 : 1;
|
||||
|
||||
std::string cmd = argv[1];
|
||||
std::vector<std::string> argvec;
|
||||
for (int i=0; i<argc; i++)
|
||||
argvec.push_back(argv[i]);
|
||||
|
||||
|
||||
if (cmd == "autocomplete")
|
||||
if (cmd == "autocomplete") {
|
||||
std::vector<std::string> argvec;
|
||||
for (int i=0; i<argc; i++)
|
||||
argvec.push_back(argv[i]);
|
||||
return autocomplete(argvec) ? 0 : 1;
|
||||
}
|
||||
|
||||
if (cmd == "help" || cmd == "-h" || cmd == "--help" || cmd== "h" || cmd=="halp")
|
||||
return print_help() ? 0 : 1;
|
||||
@ -216,30 +218,32 @@ int main(int argc, char* argv[]) {
|
||||
std::set<std::string> commands;
|
||||
get_all_used_commands(commands);
|
||||
commands.merge(std::set<std::string>{"ssh","edit","_allservicesstatus"}); // handled by service_runner, but not in template_shell_commands.
|
||||
for (const auto& command : commands) {
|
||||
if (cmd == command) {
|
||||
ServerAndServices server_and_services;
|
||||
if (!getCLIServices(safearg(argc, argv, 2), safearg(argc, argv, 3), server_and_services)) {
|
||||
std::cerr << "Error: " << command << " command requires server name and optionally service name" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (const auto& service_info : server_and_services.servicelist) {
|
||||
service_runner runner(server_and_services.server_name, service_info.service_name);
|
||||
if (!runner.isValid()) {
|
||||
std::cerr << "Error: Failed to initialize service" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::vector<std::string> additional_args;
|
||||
for (int i=4; i<argc; i++)
|
||||
additional_args.push_back(argv[i]);
|
||||
if (!runner.run_command(command, additional_args)) {
|
||||
std::cerr << command +" failed." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
if (commands.count(cmd)) {
|
||||
std::set<std::string> safe_commands = {"nuke", "fullnuke"};
|
||||
if (safe_commands.count(cmd) && argc < 4)
|
||||
return die("Error: "+cmd+" requires a server name and service name. For safety, can't run on all services.");
|
||||
|
||||
// get all the services to run the command on.
|
||||
ServerAndServices server_and_services;
|
||||
if (!getCLIServices(safearg(argc, argv, 2), safearg(argc, argv, 3), server_and_services))
|
||||
return die("Error: "+cmd+" command requires server name and optionally service name");
|
||||
|
||||
// run the command on each service.
|
||||
for (const auto& service_info : server_and_services.servicelist) {
|
||||
service_runner runner(server_and_services.server_name, service_info.service_name);
|
||||
if (!runner.isValid())
|
||||
return die("Error: Failed to initialize service");
|
||||
|
||||
std::vector<std::string> additional_args;
|
||||
for (int i=4; i<argc; i++)
|
||||
additional_args.push_back(argv[i]);
|
||||
if (!runner.run_command(cmd, additional_args))
|
||||
return die(cmd+" failed.");
|
||||
}
|
||||
|
||||
// success!
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Unknown command
|
||||
|
Reference in New Issue
Block a user