Add triggershell service logs command
Thin wrapper around journalctl, consistent with the existing status/uninstall wrappers around systemctl.
This commit is contained in:
@@ -113,6 +113,7 @@ the script — always as a discrete argv element or env var, never interpolated
|
|||||||
| `triggershell service install [--system]` | Install a systemd unit that runs `triggershell start` (per-user by default, Linux only) |
|
| `triggershell service install [--system]` | Install a systemd unit that runs `triggershell start` (per-user by default, Linux only) |
|
||||||
| `triggershell service uninstall [--system]` | Stop, disable, and remove the systemd unit |
|
| `triggershell service uninstall [--system]` | Stop, disable, and remove the systemd unit |
|
||||||
| `triggershell service status [--system]` | Show the systemd unit's status |
|
| `triggershell service status [--system]` | Show the systemd unit's status |
|
||||||
|
| `triggershell service logs [-n LINES] [--no-follow] [--system]` | Tail the systemd unit's logs (wraps `journalctl`) |
|
||||||
|
|
||||||
### Running scripts from the CLI
|
### Running scripts from the CLI
|
||||||
|
|
||||||
|
|||||||
@@ -74,9 +74,9 @@ installs a per-user unit (`~/.config/systemd/user/triggershell.service`, no root
|
|||||||
targets `/etc/systemd/system/` instead and prints the `sudo` commands to run if not already root.
|
targets `/etc/systemd/system/` instead and prints the `sudo` commands to run if not already root.
|
||||||
`install` reloads the systemd daemon but does not enable/start the unit itself — that's a separate,
|
`install` reloads the systemd daemon but does not enable/start the unit itself — that's a separate,
|
||||||
explicit `systemctl --user enable --now triggershell`, since it's the point where the service
|
explicit `systemctl --user enable --now triggershell`, since it's the point where the service
|
||||||
actually starts listening and running scripts. `triggershell service status`/`uninstall` are thin
|
actually starts listening and running scripts. `triggershell service status`/`uninstall`/`logs` are
|
||||||
wrappers around `systemctl`; log tailing is just `journalctl --user -u triggershell -f` — not
|
thin wrappers around `systemctl`/`journalctl` respectively - no unit-file parsing or log storage of
|
||||||
reimplemented.
|
our own, journald already does that.
|
||||||
|
|
||||||
## Cross-module-graph state
|
## Cross-module-graph state
|
||||||
|
|
||||||
|
|||||||
@@ -126,3 +126,24 @@ export async function serviceStatusCommand(
|
|||||||
});
|
});
|
||||||
process.exitCode = result.exitCode ?? 1;
|
process.exitCode = result.exitCode ?? 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ServiceLogsOptions extends ServiceScopeOptions {
|
||||||
|
follow?: boolean;
|
||||||
|
lines?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function serviceLogsCommand(
|
||||||
|
opts: ServiceLogsOptions,
|
||||||
|
): Promise<void> {
|
||||||
|
const scope = scopeOf(opts);
|
||||||
|
const args = scope === "user" ? ["--user"] : [];
|
||||||
|
args.push("-u", SERVICE_NAME);
|
||||||
|
if (opts.follow !== false) args.push("-f");
|
||||||
|
if (opts.lines !== undefined) args.push("-n", String(opts.lines));
|
||||||
|
|
||||||
|
const result = await execa("journalctl", args, {
|
||||||
|
stdio: "inherit",
|
||||||
|
reject: false,
|
||||||
|
});
|
||||||
|
process.exitCode = result.exitCode ?? 1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { runCommand } from "./commands/run";
|
|||||||
import { scriptsListCommand, scriptsShowCommand } from "./commands/scripts";
|
import { scriptsListCommand, scriptsShowCommand } from "./commands/scripts";
|
||||||
import {
|
import {
|
||||||
serviceInstallCommand,
|
serviceInstallCommand,
|
||||||
|
serviceLogsCommand,
|
||||||
serviceStatusCommand,
|
serviceStatusCommand,
|
||||||
serviceUninstallCommand,
|
serviceUninstallCommand,
|
||||||
} from "./commands/service";
|
} from "./commands/service";
|
||||||
@@ -180,6 +181,25 @@ service
|
|||||||
)
|
)
|
||||||
.action(serviceStatusCommand);
|
.action(serviceStatusCommand);
|
||||||
|
|
||||||
|
service
|
||||||
|
.command("logs")
|
||||||
|
.description("Tail the systemd unit's logs (journalctl).")
|
||||||
|
.option(
|
||||||
|
"-n, --lines <n>",
|
||||||
|
"Number of recent log lines to show.",
|
||||||
|
(v) => Number(v),
|
||||||
|
)
|
||||||
|
.option(
|
||||||
|
"--no-follow",
|
||||||
|
"Print recent logs and exit instead of tailing continuously.",
|
||||||
|
)
|
||||||
|
.option(
|
||||||
|
"--system",
|
||||||
|
"Target the system-wide unit instead of the per-user one.",
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.action(serviceLogsCommand);
|
||||||
|
|
||||||
if (process.argv.length <= 2) {
|
if (process.argv.length <= 2) {
|
||||||
program.outputHelp();
|
program.outputHelp();
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user