You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is sometimes useful to update the running code and / or configuration of a
network service, without disrupting existing connections. Usually, this is
achieved by starting a new process, somehow transferring clients to it and
then exiting the old process.
There are many ways to implement graceful upgrades.
They vary wildly in the trade-offs they make, and how much control they afford the user. This library
has the following goals:
No old code keeps running after a successful upgrade
The new process has a grace period for performing initialisation
Crashing during initialisation is OK
Only a single upgrade is ever run in parallel
tableflip works on Linux and macOS.
Using the library
upg, _:=tableflip.New(tableflip.Options{})
deferupg.Stop()
gofunc() {
sig:=make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGHUP)
forrangesig {
upg.Upgrade()
}
}()
// Listen must be called before Readyln, _:=upg.Listen("tcp", "localhost:8080")
deferln.Close()
gohttp.Serve(ln, nil)
iferr:=upg.Ready(); err!=nil {
panic(err)
}
<-upg.Exit()
The logs of a process using tableflip may go missing due to a bug in journald,
which has been fixed by systemd v244 release. If you are running an older version
of systemd, you can work around this by logging directly to journald, for example
by using go-systemd/journal
and looking for the $JOURNAL_STREAM
environment variable.