reboot: send SIGTERM to processes, wait for 1s
This way, programs can flush state to permanent storage if they need to.
This commit is contained in:
parent
6c059494af
commit
91da7026f8
18
supervise.go
18
supervise.go
@ -205,6 +205,10 @@ func redirectToStatus(w http.ResponseWriter, r *http.Request, path string) {
|
||||
http.Redirect(w, r, u.String(), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
// killSupervisedServices is called before rebooting when upgrading, allowing
|
||||
// processes to terminate in an orderly fashion.
|
||||
var killSupervisedServices = func() {}
|
||||
|
||||
func superviseServices(services []*service) {
|
||||
for _, s := range services {
|
||||
go supervise(s)
|
||||
@ -219,6 +223,20 @@ func superviseServices(services []*service) {
|
||||
return nil
|
||||
}
|
||||
|
||||
killSupervisedServices = func() {
|
||||
for _, s := range services {
|
||||
if s.Stopped() {
|
||||
continue
|
||||
}
|
||||
|
||||
s.setStopped(true)
|
||||
|
||||
if p := s.Process(); p != nil {
|
||||
p.Signal(syscall.SIGTERM)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
http.HandleFunc("/stop", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "expected a POST request", http.StatusBadRequest)
|
||||
|
16
update.go
16
update.go
@ -166,14 +166,16 @@ func initUpdate() error {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: implement a shutdown sequence, i.e. kill + timeout + term; unmount, then force-unmount?
|
||||
|
||||
if err := syscall.Unmount("/perm", unix.MNT_FORCE); err != nil {
|
||||
log.Printf("unmounting /perm failed: %v", err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
time.Sleep(1 * time.Second) // give the HTTP response some time to be sent
|
||||
killSupervisedServices()
|
||||
|
||||
// give the HTTP response some time to be sent; allow processes some time to terminate
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
if err := syscall.Unmount("/perm", unix.MNT_FORCE); err != nil {
|
||||
log.Printf("unmounting /perm failed: %v", err)
|
||||
}
|
||||
|
||||
if err := unix.Reboot(unix.LINUX_REBOOT_CMD_RESTART); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user