logs command
This commit is contained in:
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)...)
|
||||
|
||||
Reference in New Issue
Block a user