kill all processes correctly for micro kill command (#1633)
This commit is contained in:
parent
09d1450d7d
commit
05858b746c
@ -536,7 +536,7 @@ func (r *runtime) Delete(s *Service, opts ...DeleteOption) error {
|
|||||||
}
|
}
|
||||||
if s, ok := r.services[serviceKey(s)]; ok {
|
if s, ok := r.services[serviceKey(s)]; ok {
|
||||||
// check if running
|
// check if running
|
||||||
if s.Running() {
|
if !s.Running() {
|
||||||
delete(r.services, s.key())
|
delete(r.services, s.key())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ func (p *Process) Exec(exe *process.Executable) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Fork(exe *process.Executable) (*process.PID, error) {
|
func (p *Process) Fork(exe *process.Executable) (*process.PID, error) {
|
||||||
|
|
||||||
// create command
|
// create command
|
||||||
cmd := exec.Command(exe.Package.Path, exe.Args...)
|
cmd := exec.Command(exe.Package.Path, exe.Args...)
|
||||||
|
|
||||||
@ -43,7 +44,6 @@ func (p *Process) Fork(exe *process.Executable) (*process.PID, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// start the process
|
// start the process
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -62,22 +62,14 @@ func (p *Process) Kill(pid *process.PID) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if _, err := os.FindProcess(id); err != nil {
|
||||||
pr, err := os.FindProcess(id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// now kill it
|
// now kill it
|
||||||
err = pr.Kill()
|
// using -ve PID kills the process group which we created in Fork()
|
||||||
|
return syscall.Kill(-id, syscall.SIGKILL)
|
||||||
|
|
||||||
// kill the group
|
|
||||||
if pgid, err := syscall.Getpgid(id); err == nil {
|
|
||||||
syscall.Kill(-pgid, syscall.SIGKILL)
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the kill error
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Wait(pid *process.PID) error {
|
func (p *Process) Wait(pid *process.PID) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user