Skip to content

Commit 9bf32e7

Browse files
idoubiclaude
andcommitted
Fix update command restart: use daemon flow with proper pid/log handling
The update restart was launching `weclaw start` without -f flag and without the daemon setup (log file, pid file, setsid), causing pid=-1 and failed restarts. Now uses runDaemon() and waits for old process to exit before starting the new one. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8f02c29 commit 9bf32e7

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

cmd/update.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os/exec"
1111
"runtime"
1212
"strings"
13+
"time"
1314

1415
"github.com/spf13/cobra"
1516
)
@@ -89,22 +90,24 @@ func runUpdate(cmd *cobra.Command, args []string) error {
8990
// 4. Restart if running in background
9091
pid, pidErr := readPid()
9192
if pidErr == nil && processExists(pid) {
92-
fmt.Println("Restarting background service...")
93-
// Stop old process
93+
fmt.Println("Stopping old process...")
9494
if p, err := os.FindProcess(pid); err == nil {
9595
p.Signal(os.Interrupt)
9696
}
97+
// Wait for old process to exit
98+
for i := 0; i < 20; i++ {
99+
if !processExists(pid) {
100+
break
101+
}
102+
time.Sleep(500 * time.Millisecond)
103+
}
97104
os.Remove(pidFile())
98105

99-
// Start new process
100-
newCmd := exec.Command(exePath, "start")
101-
if err := newCmd.Start(); err != nil {
106+
fmt.Println("Starting new version...")
107+
if err := runDaemon(); err != nil {
102108
log.Printf("Failed to restart: %v", err)
103109
fmt.Println("Update complete. Please run 'weclaw start' manually.")
104-
return nil
105110
}
106-
newCmd.Process.Release()
107-
fmt.Printf("Restarted (pid=%d)\n", newCmd.Process.Pid)
108111
} else {
109112
fmt.Println("Update complete. Run 'weclaw start' to start.")
110113
}

0 commit comments

Comments
 (0)