Update TEMPLATES.md
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 26s
Build-Test-Publish / build (linux/arm64) (push) Successful in 1m3s

This commit is contained in:
j
2026-01-26 21:14:32 +13:00
parent 87fee40117
commit c9fade95e9
2 changed files with 86 additions and 1 deletions

View File

@@ -296,7 +296,7 @@ esac
``` ```
### logs.sh ### logs.sh
Shows container logs: Shows container logs. **OPTIONAL** - if provided, `dropshell log SERVER SERVICE` (or `dropshell logs`) will execute this script and display the output.
```bash ```bash
#!/bin/bash #!/bin/bash
@@ -306,6 +306,12 @@ _check_required_env_vars "CONTAINER_NAME"
docker logs "$CONTAINER_NAME" "$@" docker logs "$CONTAINER_NAME" "$@"
``` ```
**Usage:**
```bash
dropshell log myserver myservice
dropshell logs myserver myservice # Alias
```
### check-config.sh ### check-config.sh
Validates the service configuration without restarting or modifying the service. **OPTIONAL** - if not provided, `dropshell check-config` reports that the template doesn't support this command. Validates the service configuration without restarting or modifying the service. **OPTIONAL** - if not provided, `dropshell check-config` reports that the template doesn't support this command.

View 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