A lightweight self-upgrading component for Go CLI/daemon apps.
- Single binary supports self-upgrade
- Version check from HTTP (v-x.y.z)
- Locks to avoid systemd/supervisor restart conflict
- Configurable executable path and URLs
- Easy to import and use
up := selfupdate.New(selfupdate.Config{
Version: "v-1.0.0",
CheckURL: "http://localhost:8080/version.txt",
UpgradeURL: "http://localhost:8080/myapp",
ExecutablePath: "/usr/local/bin/myapp",
LockFile: "/tmp/myapp.lock",
Println: fmt.Println,
})
up.MaybeUpgrade()
go build -o myapp main.go
cp./myapp /usr/local/bin/myapp
cp./system/myapp.service /etc/systemd/system/
systemctl daemon-reexec
systemctl enable --now myapp.service
MIT