Write response before shutting down

This commit is contained in:
Jakob Borg 2014-05-12 21:15:18 -03:00
parent 30ea9cb37e
commit 1bf07d6b58
1 changed files with 12 additions and 3 deletions

View File

@ -157,19 +157,28 @@ func restGetConfigInSync(w http.ResponseWriter) {
json.NewEncoder(w).Encode(map[string]bool{"configInSync": configInSync})
}
func restPostRestart() {
func restPostRestart(w http.ResponseWriter) {
flushResponse(`{"ok": "restarting"}`, w)
go restart()
}
func restPostReset() {
func restPostReset(w http.ResponseWriter) {
flushResponse(`{"ok": "resetting repos"}`, w)
resetRepositories()
go restart()
}
func restPostShutdown() {
func restPostShutdown(w http.ResponseWriter) {
flushResponse(`{"ok": "shutting down"}`, w)
go shutdown()
}
func flushResponse(s string, w http.ResponseWriter) {
w.Write([]byte(s + "\n"))
f := w.(http.Flusher)
f.Flush()
}
var cpuUsagePercent [10]float64 // The last ten seconds
var cpuUsageLock sync.RWMutex