Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for a go binary to reload itself?

Tags:

go

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

like image 312
Marc Avatar asked Jan 07 '15 15:01

Marc


1 Answers

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

like image 50
Not_a_Golfer Avatar answered Oct 21 '22 04:10

Not_a_Golfer