golang http graceful restart
package main
import (
"net/http"
"io"
"github.com/Yooke/go-graceful"
)
func main() {
http.HandleFunc("/", ping)
graceful.ListenAndServe(&http.Server{Addr: ":8000"}, "/var/run/app.pid")
}
func ping(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "pong")
}
[Unit]
Description=Application Desc
After=network.target
[Service]
Type=simple
PIDFile=/var/run/app.pid
ExecStart=/path/to/app
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target