From ae2c10b6464311e8a295c07905ce1dbae1341bda Mon Sep 17 00:00:00 2001 From: Nick Goodall Date: Tue, 13 Jan 2026 13:51:36 +0000 Subject: [PATCH] logs command --- README.md | 4 +++- deploy.go | 27 +++++++++++++++++++++++++++ main.go | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9219ea8..1b3a577 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ Provision a remote PocketBase server. This will: Syncs `pb_public`, `pb_migrations`, and `pb_hooks`, then restarts the remote PocketBase service. The command will automatically run `setup` if the PocketBase binary isn’t present on the remote. -### logs +### `logs` + +Connects to the configured server and streams `/root/pb/{service}/{service}.log` via `tail -n 100 -F`. ### secrets diff --git a/deploy.go b/deploy.go index a4d211f..e2f00b4 100644 --- a/deploy.go +++ b/deploy.go @@ -209,6 +209,25 @@ func runDeploy() error { return nil } +func runLogs() error { + ctx, err := buildDeploymentContext() + if err != nil { + return err + } + defer closeSSHControlMaster(ctx.serverIP) + + logPath := filepath.Join(ctx.serviceDir, fmt.Sprintf("%s.log", ctx.serviceName)) + script := fmt.Sprintf(`set -euo pipefail +log=%s +if [ ! -f "$log" ]; then + echo "log file not found: $log" >&2 + exit 1 +fi +tail -n 25 -F "$log" +`, shellQuote(logPath)) + return runSSHRawCommand(ctx.serverIP, script) +} + func remoteBinaryExists(server, path string) (bool, error) { script := fmt.Sprintf(`if [ -f %q ]; then printf yes; else printf no; fi`, path) output, err := runSSHOutput(server, script) @@ -420,6 +439,14 @@ func runSSHCommand(server, script string) error { return pipeErr } +func runSSHRawCommand(server, script string) error { + remoteCmd := fmt.Sprintf("bash --noprofile --norc -c %s", shellQuote(script)) + cmd := exec.Command("ssh", append(sshArgs(server), remoteCmd)...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() +} + func runSSHOutput(server, script string) (string, error) { remoteCmd := fmt.Sprintf("bash --noprofile --norc -c %s", shellQuote(script)) cmd := exec.Command("ssh", append(sshArgs(server), remoteCmd)...) diff --git a/main.go b/main.go index 63da1ce..bdad531 100644 --- a/main.go +++ b/main.go @@ -62,7 +62,7 @@ func defaultCommands() []command { {name: "dev", description: "run the PocketBase binary locally", action: runDev}, {name: "setup", description: "provision the remote server and install PocketBase", action: runSetup}, {name: "deploy", description: "sync migrations/hooks/static assets (runs setup if needed)", action: runDeploy}, - {name: "logs", description: "show PocketBase logs", action: placeholderAction("logs")}, + {name: "logs", description: "show PocketBase logs", action: runLogs}, {name: "secrets", description: "manage deployment secrets", action: placeholderAction("secrets")}, } }