Introduce Group config option
This commit is contained in:
parent
7f5c354d04
commit
f5fce902e8
@ -35,6 +35,14 @@ processes:
|
||||
# process to exit before sending it a SIGKILL (aka a kill -9).
|
||||
sigKillWait: 10s
|
||||
|
||||
# group can be used to control the order and grouping of processes as they
|
||||
# shut down.
|
||||
#
|
||||
# Processes will not be shut down until all processes with a higher group
|
||||
# number are already shut down. Processes with the same group number will be
|
||||
# shut down simultaneously.
|
||||
group: 1
|
||||
|
||||
# This process will not immediately exit when pmux tells it to do so, but pmux
|
||||
# will SIGKILL it after sigKillWait has elapsed.
|
||||
stubborn-pinger:
|
||||
|
@ -68,9 +68,25 @@ func (p *Pmux) Restart(name string) {
|
||||
func (p *Pmux) Stop() {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
p.sysLogger.Println("killing child processes")
|
||||
var minGroup, maxGroup int
|
||||
|
||||
for _, proc := range p.processes {
|
||||
if maxGroup < proc.cfg.Group {
|
||||
maxGroup = proc.cfg.Group
|
||||
}
|
||||
|
||||
if minGroup > proc.cfg.Group {
|
||||
minGroup = proc.cfg.Group
|
||||
}
|
||||
}
|
||||
|
||||
for group := maxGroup; group >= minGroup; group-- {
|
||||
p.sysLogger.Printf("killing child processes (group %d)", group)
|
||||
for _, proc := range p.processes {
|
||||
proc := proc
|
||||
if proc.cfg.Group != group {
|
||||
continue
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
@ -78,7 +94,8 @@ func (p *Pmux) Stop() {
|
||||
proc.Stop()
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
p.sysLogger.Println("exited gracefully, ciao!")
|
||||
}
|
||||
|
@ -49,6 +49,14 @@ type ProcessConfig struct {
|
||||
// this function returns. If used with RunProcessOnce and an error is
|
||||
// returned, RunProcessOnce will return that error.
|
||||
StartAfterFunc func(context.Context) error
|
||||
|
||||
// Group can be used to control the order and grouping of processes as they
|
||||
// shut down.
|
||||
//
|
||||
// Processes will not be shut down until all processes with a higher group
|
||||
// number are already shut down. Processes with the same group number will
|
||||
// be shut down simultaneously.
|
||||
Group int
|
||||
}
|
||||
|
||||
func (cfg ProcessConfig) withDefaults() ProcessConfig {
|
||||
|
Loading…
Reference in New Issue
Block a user