77 "os/exec"
88 "os/signal"
99 "path/filepath"
10- "runtime"
1110 "strings"
1211 "sync"
1312 "syscall"
@@ -17,6 +16,7 @@ import (
1716 "github.com/charmbracelet/lipgloss"
1817 "github.com/memodb-io/Acontext/acontext-cli/internal/docker"
1918 "github.com/memodb-io/Acontext/acontext-cli/internal/pkgmgr"
19+ "github.com/memodb-io/Acontext/acontext-cli/internal/platform"
2020 "github.com/memodb-io/Acontext/acontext-cli/internal/sandbox"
2121 "github.com/spf13/cobra"
2222)
@@ -516,9 +516,7 @@ func runServerUp(cmd *cobra.Command, args []string) error {
516516 mu .Lock ()
517517 sandboxCmd = exec .Command (parts [0 ], parts [1 :]... )
518518 sandboxCmd .Dir = projectDir
519- if runtime .GOOS != "windows" {
520- sandboxCmd .SysProcAttr = & syscall.SysProcAttr {Setpgid : true }
521- }
519+ platform .SetProcessGroup (sandboxCmd )
522520 mu .Unlock ()
523521
524522 sandboxStdout , err := sandboxCmd .StdoutPipe ()
@@ -689,25 +687,12 @@ func runServerUp(cmd *cobra.Command, args []string) error {
689687func cleanup (cwd string , mu * sync.Mutex , sandboxCmd , dockerLogsCmd * exec.Cmd , dockerComposeFile string ) {
690688 mu .Lock ()
691689 if sandboxCmd != nil && sandboxCmd .Process != nil {
692- if runtime .GOOS != "windows" {
693- pgid , err := syscall .Getpgid (sandboxCmd .Process .Pid )
694- if err == nil {
695- if err := syscall .Kill (- pgid , syscall .SIGTERM ); err != nil {
696- fmt .Printf ("⚠️ Warning: failed to send SIGTERM to process group: %v\n " , err )
697- }
698- time .Sleep (500 * time .Millisecond )
699- if err := syscall .Kill (- pgid , syscall .SIGKILL ); err != nil {
700- fmt .Printf ("⚠️ Warning: failed to send SIGKILL to process group: %v\n " , err )
701- }
702- } else {
703- if err := sandboxCmd .Process .Kill (); err != nil {
704- fmt .Printf ("⚠️ Warning: failed to kill sandbox process: %v\n " , err )
705- }
706- }
707- } else {
708- if err := sandboxCmd .Process .Kill (); err != nil {
709- fmt .Printf ("⚠️ Warning: failed to kill sandbox process: %v\n " , err )
710- }
690+ if err := platform .KillProcessGroup (sandboxCmd ); err != nil {
691+ fmt .Printf ("⚠️ Warning: failed to send SIGTERM to process group: %v\n " , err )
692+ }
693+ time .Sleep (500 * time .Millisecond )
694+ if err := platform .KillProcessGroupForce (sandboxCmd ); err != nil {
695+ fmt .Printf ("⚠️ Warning: failed to send SIGKILL to process group: %v\n " , err )
711696 }
712697 if err := sandboxCmd .Wait (); err != nil {
713698 fmt .Printf ("⚠️ Warning: sandbox process wait error: %v\n " , err )
0 commit comments