logs command
This commit is contained in:
@@ -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
|
||||
|
||||
27
deploy.go
27
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)...)
|
||||
|
||||
2
main.go
2
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")},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user