Skip to content

Commit

Permalink
Merge pull request #2574 from nirs/background-fix
Browse files Browse the repository at this point in the history
Run in a new process group when not using --foreground
AkihiroSuda authored Sep 1, 2024
2 parents 726f61d + 47a3d7b commit e2d123f
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pkg/instance/ha_cmd_opts_others.go
Original file line number Diff line number Diff line change
@@ -6,4 +6,7 @@ import (
"syscall"
)

var SysProcAttr = &syscall.SysProcAttr{}
var (
ForegroundSysProcAttr = &syscall.SysProcAttr{}
BackgroundSysProcAttr = &syscall.SysProcAttr{Setpgid: true}
)
9 changes: 6 additions & 3 deletions pkg/instance/ha_cmd_opts_windows.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,9 @@ import (
"syscall"
)

var SysProcAttr = &syscall.SysProcAttr{
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
}
var (
ForegroundSysProcAttr = &syscall.SysProcAttr{}
BackgroundSysProcAttr = &syscall.SysProcAttr{
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
}
)
7 changes: 6 additions & 1 deletion pkg/instance/start.go
Original file line number Diff line number Diff line change
@@ -189,7 +189,12 @@ func Start(ctx context.Context, inst *store.Instance, launchHostAgentForeground
}
args = append(args, inst.Name)
haCmd := exec.CommandContext(ctx, self, args...)
haCmd.SysProcAttr = SysProcAttr

if launchHostAgentForeground {
haCmd.SysProcAttr = ForegroundSysProcAttr
} else {
haCmd.SysProcAttr = BackgroundSysProcAttr
}

haCmd.Stdout = haStdoutW
haCmd.Stderr = haStderrW

0 comments on commit e2d123f

Please sign in to comment.