Is it possible for the go binary to reload?
I am using go-update ( https://github.com/inconshreveable/go-update ) to update the Go binary that I distribute to users. Right now, when a running program launches a new version, it sends a message to the user asking them to exit and restart the program.
Is it possible for a running go program to reload from a new binary?
This has been asked in the update issue tracker, but there is no answer: https://github.com/inconshreveable/go-update/issues/5
source to share
Yes, you can use os.Args
one that contains the executable name of the current process and a package os.exec
that can start and fork. A good example is how this is done in a package goagain
that supports zero reloading. In fact, you can probably just use it.
See https://github.com/rcrowley/goagain
and more specifically in this file: https://github.com/rcrowley/goagain/blob/master/goagain.go#L77
source to share