logs command

This commit is contained in:
2026-01-13 13:51:36 +00:00
parent a865b1b2c7
commit ae2c10b646
3 changed files with 31 additions and 2 deletions

View File

@@ -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)...)