Monitorable, gracefully restarting, self-upgrading binaries in Go (golang)
Monitorable, gracefully restarting, self-upgrading binaries in Go (golang)
overseer is a package for creating monitorable, gracefully restarting, self-upgrading binaries in Go (golang). The main goal of this project is to facilitate the creation of self-upgrading binaries which play nice with standard process managers, secondly it should expose a small and simple API with reasonable defaults.
Commonly, graceful restarts are performed by the active process (dark blue) closing its listeners and passing these matching listening socket files (green) over to a newly started process. This restart causes any foreground process monitoring to incorrectly detect a program crash. overseer attempts to solve this by using a small process to perform this socket file exchange and proxying signals and exit code from the active process.
go get github.com/jpillora/overseerThis program works with process managers, supports graceful, zero-down time restarts and self-upgrades its own binary.
…How it works:
overseer uses the main process to check for and install upgrades and a child process to run Program.Address/es.Listener/s for the Program to consume.Fetcher runs in a goroutine and checks for updates at preconfigured interval. When Fetcher returns a valid binary stream (io.Reader), the master process saves it to a temporary location, verifies it, replaces the current binary and initiates a graceful restart.fetcher.HTTP accepts a URL, it polls this URL with HEAD requests and until it detects a change. On change, we GET the URL and stream it back out to overseer. See also fetcher.S3.overseer binary.overseer is not a process manager.See Configuration options here and the runtime State available to your program here.
See the example/ directory and run example.sh, you should see the following output:
…Note: app#1 stays running until the last request is closed.
func main() {
overseer.Run(overseer.Config{
Program: prog,
Address: ":3000",
})
}Send main a SIGUSR2 (Config.RestartSignal) to manually trigger a restart
func main() {
overseer.Run(overseer.Config{
Program: prog,
NoRestart: true,
Fetcher: &fetcher.HTTP{
URL: "http://localhost:4000/binaries/myapp",
Interval: 1 * time.Second,
},
})
}Your binary will be upgraded though it will require manual restart from the user, suitable for creating self-upgrading command-line applications.
URLfunc main() {
overseer.Run(overseer.Config{
Program: prog,
Fetcher: &fetcher.HTTP{
URL: "http://localhost:4000/binaries/app-"+runtime.GOOS+"-"+runtime.GOARCH,
//e.g.http://localhost:4000/binaries/app-linux-amd64
},
})
}overseer.Config cannot be changed via an upgrade, the master process must be restarted.Addresses can only be changed by restarting the main process.mv for moving files because mv handles cross-partition moves unlike os.Rename.init() functions will run twice on start, once in the main process and once in the child process.See CONTRIBUTING.md
No open issues yet, or sync has not completed.