Skip to content

Commit 7b81fea

Browse files
committed
Wait on the watcher at startup instead of releasing.
1 parent e401afe commit 7b81fea

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

internal/pkg/agent/application/upgrade/rollback.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,24 @@ func InvokeWatcher(log *logger.Logger, agentExecutable string) (*exec.Cmd, error
146146
}
147147

148148
cmd := invokeCmd(agentExecutable)
149-
defer func() {
150-
if cmd.Process != nil {
151-
log.Infof("releasing watcher %v", cmd.Process.Pid)
152-
_ = cmd.Process.Release()
153-
}
154-
}()
155-
156149
log.Infow("Starting upgrade watcher", "path", cmd.Path, "args", cmd.Args, "env", cmd.Env, "dir", cmd.Dir)
157150
if err := cmd.Start(); err != nil {
158151
return nil, fmt.Errorf("failed to start Upgrade Watcher: %w", err)
159152
}
160153

161154
upgradeWatcherPID := cmd.Process.Pid
162155
agentPID := os.Getpid()
156+
157+
go func() {
158+
if err := cmd.Wait(); err != nil {
159+
log.Infow("Upgrade Watcher exited with error", "agent.upgrade.watcher.process.pid", "agent.process.pid", agentPID, upgradeWatcherPID, "error.message", err)
160+
}
161+
}()
162+
163163
log.Infow("Upgrade Watcher invoked", "agent.upgrade.watcher.process.pid", upgradeWatcherPID, "agent.process.pid", agentPID)
164164

165165
return cmd, nil
166+
166167
}
167168

168169
func restartAgent(ctx context.Context, log *logger.Logger, c client.Client) error {

0 commit comments

Comments
 (0)