Skip to content

Commit 91bc703

Browse files
committed
fix: run update command as detached process
1 parent 61bab5b commit 91bc703

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//go:build darwin || linux
2+
3+
package main
4+
5+
import (
6+
"os"
7+
"os/exec"
8+
"syscall"
9+
)
10+
11+
func detachedCommand(path string, args []string, stdout, stderr *os.File) *exec.Cmd {
12+
cmd := exec.Command(path, args...)
13+
cmd.Stdout = stdout
14+
cmd.Stderr = stderr
15+
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
16+
return cmd
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//go:build windows
2+
3+
package main
4+
5+
import (
6+
"os"
7+
"os/exec"
8+
"syscall"
9+
)
10+
11+
func detachedCommand(path string, args []string, stdout, stderr *os.File) *exec.Cmd {
12+
cmd := exec.Command(path, args...)
13+
cmd.Stdout = stdout
14+
cmd.Stderr = stderr
15+
cmd.SysProcAttr = &syscall.SysProcAttr{
16+
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
17+
}
18+
return cmd
19+
}

cmd/agent_smith/service.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"io"
99
"net/http"
1010
"os"
11-
"os/exec"
1211
"runtime"
1312
"strings"
1413
"time"
@@ -109,7 +108,7 @@ func (svc *serviceContext) Execute(
109108
&device,
110109
"https://api.github.com/repos/rewstapp/agent-smith-go/releases/latest",
111110
func(path string, args []string) error {
112-
return exec.Command(path, args...).Start()
111+
return detachedCommand(path, args, logFile, logFile).Start()
113112
},
114113
)
115114
runner := agent.NewAutoUpdateRunner(logger, updater, agent.DefaultUpdateInterval(), 5, 5*time.Minute)

0 commit comments

Comments
 (0)