(rw http.ResponseWriter, req *http.Request)
| 298 | } |
| 299 | |
| 300 | func (sh *StatusHandler) serveRestart(rw http.ResponseWriter, req *http.Request) { |
| 301 | if req.Method != "POST" { |
| 302 | http.Error(rw, "POST to restart", http.StatusMethodNotAllowed) |
| 303 | return |
| 304 | } |
| 305 | |
| 306 | _, handlers := sh.handlerFinder.AllHandlers() |
| 307 | for _, h := range handlers { |
| 308 | ah, ok := h.(*app.Handler) |
| 309 | if !ok { |
| 310 | continue |
| 311 | } |
| 312 | log.Printf("Sending SIGINT to %s", ah.ProgramName()) |
| 313 | err := ah.Quit() |
| 314 | if err != nil { |
| 315 | msg := fmt.Sprintf("Not restarting: couldn't interrupt app %s: %v", ah.ProgramName(), err) |
| 316 | log.Print(msg) |
| 317 | http.Error(rw, msg, http.StatusInternalServerError) |
| 318 | return |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | reindex := (req.FormValue("reindex") == "on") |
| 323 | recovery, _ := strconv.Atoi(req.FormValue("recovery")) |
| 324 | |
| 325 | log.Println("Restarting perkeepd") |
| 326 | rw.Header().Set("Connection", "close") |
| 327 | http.Redirect(rw, req, sh.prefix, http.StatusFound) |
| 328 | if f, ok := rw.(http.Flusher); ok { |
| 329 | f.Flush() |
| 330 | } |
| 331 | osutil.RestartProcess(fmt.Sprintf("-reindex=%t", reindex), fmt.Sprintf("-recovery=%d", recovery)) |
| 332 | } |
| 333 | |
| 334 | var cgoEnabled bool |
no test coverage detected