Update TEMPLATES.md
This commit is contained in:
79
source/src/commands/log.cpp
Normal file
79
source/src/commands/log.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include "command_registry.hpp"
|
||||
#include "config.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
#include "shared_commands.hpp"
|
||||
#include "servers.hpp"
|
||||
#include "services.hpp"
|
||||
#include "utils/output.hpp"
|
||||
|
||||
namespace dropshell
|
||||
{
|
||||
|
||||
int log_handler(const CommandContext &ctx);
|
||||
|
||||
static std::vector<std::string> log_name_list = {"log", "logs"};
|
||||
|
||||
// Static registration
|
||||
struct LogCommandRegister
|
||||
{
|
||||
LogCommandRegister()
|
||||
{
|
||||
CommandRegistry::instance().register_command({log_name_list,
|
||||
log_handler,
|
||||
shared_commands::std_autocomplete,
|
||||
false, // hidden
|
||||
true, // requires_config
|
||||
true, // requires_install
|
||||
2, // min_args (after command)
|
||||
2, // max_args (after command)
|
||||
"log SERVER SERVICE",
|
||||
"View logs for a service on a server.",
|
||||
R"(
|
||||
|
||||
log SERVER SERVICE View logs for the given service on the server.
|
||||
logs SERVER SERVICE Alias for log.
|
||||
|
||||
Runs the logs.sh script on the remote server/service if it exists
|
||||
and displays the output.
|
||||
)"});
|
||||
}
|
||||
} log_command_register;
|
||||
|
||||
int log_handler(const CommandContext &ctx)
|
||||
{
|
||||
std::string server = safearg(ctx.args, 0);
|
||||
std::string service = safearg(ctx.args, 1);
|
||||
|
||||
// Check if server is disabled
|
||||
if (gConfig().is_server_disabled(server))
|
||||
{
|
||||
warning << "Server '" << server << "' is disabled." << std::endl;
|
||||
info << "Use 'dropshell enable " << server << "' to re-enable this server." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ServerConfig server_env(server);
|
||||
if (!server_env.is_valid())
|
||||
{
|
||||
error << "Server " << server << " is not valid" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!legal_service_name(service))
|
||||
{
|
||||
error << "Service name contains illegal characters: " << service << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// run the logs script
|
||||
bool okay = server_env.run_remote_template_command(service, "logs", {}, false, {}, NULL);
|
||||
|
||||
if (!okay)
|
||||
{
|
||||
error << "Failed to retrieve logs for service " << service << " on server " << server << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
||||
Reference in New Issue
Block a user