Skip to content

Commit

Permalink
fix(service): detach from process on self-update
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme committed Feb 4, 2025
1 parent 267038d commit 601855c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/humanlog/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ func (hdl *serviceHandler) DoUpdate(ctx context.Context) error {
channelName = hdl.config.ExperimentalFeatures.ReleaseChannel
}
ll.InfoContext(ctx, "starting upgrade in place")
if err := selfupdate.UpgradeInPlace(ctx, baseSiteURL, channelName, os.Stdout, os.Stderr, os.Stdin); err != nil {
if err := selfupdate.UpgradeInPlace(ctx, baseSiteURL, channelName, nil, nil, nil, true); err != nil {
return fmt.Errorf("applying self-update: %v", err)
}
ll.InfoContext(ctx, "triggering self-shutdown, hoping the service manager will restart us")
Expand Down
2 changes: 1 addition & 1 deletion cmd/humanlog/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func versionCmd(
log.Printf("you're already running the latest version: v%v", semverVersion.String())
return nil
}
return selfupdate.UpgradeInPlace(ctx, baseSiteURL, channelName, os.Stdout, os.Stderr, os.Stdin)
return selfupdate.UpgradeInPlace(ctx, baseSiteURL, channelName, os.Stdout, os.Stderr, os.Stdin, false)
},
},
},
Expand Down
11 changes: 9 additions & 2 deletions internal/pkg/selfupdate/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/cli/safeexec"
)

func UpgradeInPlace(ctx context.Context, baseSiteURL string, channelName *string, stdout, stderr io.Writer, stdin io.Reader) error {
func UpgradeInPlace(ctx context.Context, baseSiteURL string, channelName *string, stdout, stderr io.Writer, stdin io.Reader, detach bool) error {
if runtime.GOOS == "windows" {
if err := renameCurrentBinaries(); err != nil {
return err
Expand Down Expand Up @@ -44,7 +44,14 @@ func UpgradeInPlace(ctx context.Context, baseSiteURL string, channelName *string
if channelName != nil {
cmd.Env = append(cmd.Env, fmt.Sprintf("HUMANLOG_CHANNEL=%s", *channelName))
}
return cmd.Run()
if detach {
if err := cmd.Start(); err != nil {
return err
}
return cmd.Process.Release()
} else {
return cmd.Run()
}
}

func isUnderHomebrew() bool {
Expand Down

0 comments on commit 601855c

Please sign in to comment.