38 lines
781 B
Go
38 lines
781 B
Go
//go:build !windows
|
|
|
|
package compose
|
|
|
|
import (
|
|
"errors"
|
|
"os/exec"
|
|
"syscall"
|
|
"time"
|
|
)
|
|
|
|
const gracefulTerminationBound = 500 * time.Millisecond
|
|
const finalTerminationBound = 2 * time.Second
|
|
|
|
func configureProcess(command *exec.Cmd) {
|
|
command.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
|
}
|
|
|
|
func terminateProcess(command *exec.Cmd, done <-chan error) error {
|
|
if command.Process == nil {
|
|
return nil
|
|
}
|
|
_ = syscall.Kill(-command.Process.Pid, syscall.SIGINT)
|
|
select {
|
|
case <-done:
|
|
return nil
|
|
case <-time.After(gracefulTerminationBound):
|
|
}
|
|
_ = syscall.Kill(-command.Process.Pid, syscall.SIGKILL)
|
|
_ = command.Process.Kill()
|
|
select {
|
|
case <-done:
|
|
return nil
|
|
case <-time.After(finalTerminationBound):
|
|
return errors.New("Docker command could not be reaped")
|
|
}
|
|
}
|