Refactor ShutdownProcess to smaller platform-specific part

This commit is contained in:
Peter Waller
2014-05-21 08:44:06 +01:00
parent 9c2bf670ca
commit ca11ca6388
3 changed files with 14 additions and 15 deletions
+6
View File
@@ -179,3 +179,9 @@ func runStart(cmd *Command, args []string) {
f.wg.Wait()
}
func ShutdownProcesses(of *OutletFactory) {
for name, p := range processes {
ShutdownProcess(of, p, name)
}
}
+5 -9
View File
@@ -33,16 +33,12 @@ func (p *Process) Signal(signal syscall.Signal) {
}
}
func ShutdownProcesses(of *OutletFactory) {
for name, ps := range processes {
of.SystemOutput(fmt.Sprintf("sending SIGTERM to %s", name))
ps.Signal(syscall.SIGTERM)
}
func ShutdownProcess(of *OutletFactory, ps *Process, name string) {
of.SystemOutput(fmt.Sprintf("sending SIGTERM to %s", name))
ps.Signal(syscall.SIGTERM)
go func() {
time.Sleep(shutdownGraceTime)
for name, ps := range processes {
of.SystemOutput(fmt.Sprintf("sending SIGKILL to %s", name))
ps.Signal(syscall.SIGKILL)
}
of.SystemOutput(fmt.Sprintf("sending SIGKILL to %s", name))
ps.Signal(syscall.SIGKILL)
}()
}
+3 -6
View File
@@ -25,10 +25,7 @@ func (p *Process) Signal(signal syscall.Signal) {
group.Signal(signal)
}
func ShutdownProcesses(of *OutletFactory) {
for name, ps := range processes {
of.SystemOutput(fmt.Sprintf("terminating %s", name))
ps.cmd.Process.Signal(os.Kill)
}
os.Exit(1)
func ShutdownProcess(of *OutletFactory, ps *Process, name string) {
of.SystemOutput(fmt.Sprintf("terminating %s", name))
ps.cmd.Process.Signal(os.Kill)
}