支持window

This commit is contained in:
root
2025-12-06 04:34:47 +00:00
parent 1533e08425
commit 15b4176afb
6 changed files with 268 additions and 10 deletions

View File

@@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"os/signal"
"runtime"
"sort"
"strconv"
"strings"
@@ -925,21 +926,30 @@ func (b *tailBuffer) String() string {
func forwardSignals(ctx context.Context, cmd *exec.Cmd, logErrorFn func(string)) {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
signals := []os.Signal{syscall.SIGINT}
if runtime.GOOS != "windows" {
signals = append(signals, syscall.SIGTERM)
}
signal.Notify(sigCh, signals...)
go func() {
defer signal.Stop(sigCh)
select {
case sig := <-sigCh:
logErrorFn(fmt.Sprintf("Received signal: %v", sig))
if cmd.Process != nil {
cmd.Process.Signal(syscall.SIGTERM)
time.AfterFunc(time.Duration(forceKillDelay)*time.Second, func() {
if cmd.Process != nil {
cmd.Process.Kill()
}
})
if cmd.Process == nil {
return
}
if runtime.GOOS == "windows" {
_ = cmd.Process.Kill()
return
}
_ = cmd.Process.Signal(syscall.SIGTERM)
time.AfterFunc(time.Duration(forceKillDelay)*time.Second, func() {
if cmd.Process != nil {
_ = cmd.Process.Kill()
}
})
case <-ctx.Done():
}
}()
@@ -962,6 +972,11 @@ func terminateProcess(cmd *exec.Cmd) *time.Timer {
return nil
}
if runtime.GOOS == "windows" {
_ = cmd.Process.Kill()
return nil
}
_ = cmd.Process.Signal(syscall.SIGTERM)
return time.AfterFunc(time.Duration(forceKillDelay)*time.Second, func() {