added NoRestart option

master
Jaime Pillora 2016-02-17 11:25:17 +11:00
parent ca280e1a6b
commit a5ef7ca2eb
4 changed files with 16 additions and 7 deletions

View File

@ -126,7 +126,7 @@ See [Config](https://godoc.org/github.com/jpillora/overseer#Config)uration optio
func main() { func main() {
overseer.Run(overseer.Config{ overseer.Run(overseer.Config{
Program: prog, Program: prog,
NoRestartAfterFetch: true NoRestart: true,
Fetcher: &fetcher.HTTP{ Fetcher: &fetcher.HTTP{
URL: "http://localhost:4000/binaries/myapp", URL: "http://localhost:4000/binaries/myapp",
Interval: 1 * time.Second, Interval: 1 * time.Second,

View File

@ -47,7 +47,11 @@ type Config struct {
Debug bool Debug bool
//NoWarn disables warning [overseer] logs. //NoWarn disables warning [overseer] logs.
NoWarn bool NoWarn bool
//NoRestart disables all restarts, this option essentially converts
//the RestartSignal into a "ShutdownSignal".
NoRestart bool
//NoRestartAfterFetch disables automatic restarts after each upgrade. //NoRestartAfterFetch disables automatic restarts after each upgrade.
//Though manual restarts using the RestartSignal can still be performed.
NoRestartAfterFetch bool NoRestartAfterFetch bool
//Fetcher will be used to fetch binaries. //Fetcher will be used to fetch binaries.
Fetcher fetcher.Interface Fetcher fetcher.Interface

View File

@ -368,9 +368,10 @@ func (mp *master) fork() error {
} }
} }
mp.debugf("prog exited with %d", code) mp.debugf("prog exited with %d", code)
//if a restart wasn't requested, proxy //if a restarts are disabled or if it was an
//through the exit code via the main process //unexpected creash, proxy this exit straight
if !mp.restarting { //through to the main process
if mp.NoRestart || !mp.restarting {
os.Exit(code) os.Exit(code)
} }
case <-mp.descriptorsReleased: case <-mp.descriptorsReleased:

View File

@ -127,15 +127,19 @@ func (sp *slave) watchSignal() {
signal.Stop(signals) signal.Stop(signals)
sp.debugf("graceful shutdown requested") sp.debugf("graceful shutdown requested")
//master wants to restart, //master wants to restart,
sp.state.GracefulShutdown <- true close(sp.state.GracefulShutdown)
//release any sockets and notify master //release any sockets and notify master
if len(sp.listeners) > 0 { if len(sp.listeners) > 0 {
//perform graceful shutdown //perform graceful shutdown
for _, l := range sp.listeners { for _, l := range sp.listeners {
l.release(sp.Config.TerminateTimeout) l.release(sp.Config.TerminateTimeout)
} }
//signal release of held sockets //signal release of held sockets, allows master to start
sp.masterProc.Signal(SIGUSR1) //a new process before this child has actually exited.
//early restarts not supported with restarts disabled.
if !sp.NoRestart {
sp.masterProc.Signal(SIGUSR1)
}
//listeners should be waiting on connections to close... //listeners should be waiting on connections to close...
} }
//start death-timer //start death-timer