I'm using go-update (https://github.com/inconshreveable/go-update) to update a Go binary that I distribute to users. Right now, when the running go program detects a new version, it sends a message to the user asking them to to quit and restart the program.
Is it possible for the running go program to reload itself from the new binary?
This was asked in the go-update issue tracker, but no answer: https://github.com/inconshreveable/go-update/issues/5
Yes, it is possible using os.Args
which holds the executable name of the current process, and the os.exec
package that can start and fork processes. A good example is how it is done in the goagain
package, which supports zero downtime restarts. 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With