forked from goffee/goffee
rewrite
This commit is contained in:
parent
c97afa7564
commit
7f4e3c39da
4 changed files with 44 additions and 9 deletions
35
cmd/run.go
35
cmd/run.go
|
|
@ -118,6 +118,15 @@ func startRestartControllerJob(fileChangeChan chan bool, pidChan chan int, start
|
|||
if err != nil {
|
||||
fmt.Println("error stopping process: ", err.Error())
|
||||
}
|
||||
} else if runtime.GOOS == "linux" {
|
||||
pgid, err := syscall.Getpgid(pid)
|
||||
if err != nil {
|
||||
fmt.Println("error getting pgid: ", err.Error())
|
||||
}
|
||||
err = syscall.Kill(-pgid, syscall.SIGKILL)
|
||||
if err != nil {
|
||||
fmt.Println("error stopping process: ", err.Error())
|
||||
}
|
||||
} else {
|
||||
fmt.Println("not implemented for os: ", runtime.GOOS)
|
||||
}
|
||||
|
|
@ -176,6 +185,32 @@ func startServerJob(pidChan chan int, startAppChan chan bool) {
|
|||
pidChan <- pid
|
||||
}()
|
||||
}
|
||||
} else if runtime.GOOS == "linux" {
|
||||
execFile := pwd + "/tmp/" + path.Base(pwd)
|
||||
binary, lookErr := exec.LookPath("/bin/sh")
|
||||
if lookErr != nil {
|
||||
panic(lookErr)
|
||||
}
|
||||
args := []string{"/bin/sh", "-c", execFile}
|
||||
execSpec := &syscall.ProcAttr{
|
||||
Dir: pwd,
|
||||
Env: os.Environ(),
|
||||
Files: []uintptr{os.Stdin.Fd(), os.Stdout.Fd(), os.Stderr.Fd()},
|
||||
Sys: &syscall.SysProcAttr{
|
||||
Setpgid: true,
|
||||
},
|
||||
}
|
||||
pid, _, err = syscall.StartProcess(binary, args, execSpec)
|
||||
if err != nil {
|
||||
fmt.Println("error starting process: ", err.Error())
|
||||
go func() {
|
||||
pidChan <- 0
|
||||
}()
|
||||
} else {
|
||||
go func() {
|
||||
pidChan <- pid
|
||||
}()
|
||||
}
|
||||
} else {
|
||||
fmt.Println("not implemented for os: ", runtime.GOOS)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue