Merge pull request #152 from braddward/shutdown

Shutdown and Reboot functions
pull/154/head
cyoung 2015-12-19 20:08:58 -05:00
commit 2674b1076d
2 zmienionych plików z 18 dodań i 1 usunięć

Wyświetl plik

@ -10,6 +10,7 @@ import (
"log"
"net/http"
"time"
"syscall"
)
type SettingMessage struct {
@ -218,7 +219,7 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) {
log.Printf("handleSettingsSetRequest:json: unrecognized key:%s\n", key)
}
}
saveSettings()
saveSettings()
}
}
@ -228,6 +229,18 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) {
}
}
func handleShutdownRequest(w http.ResponseWriter, r *http.Request) {
syscall.Sync()
syscall.Reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF)
}
func handleRebootRequest(w http.ResponseWriter, r *http.Request) {
syscall.Sync()
syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
}
func managementInterface() {
weatherUpdate = NewUIBroadcaster()
trafficUpdate = NewUIBroadcaster()
@ -264,6 +277,8 @@ func managementInterface() {
http.HandleFunc("/getTowers", handleTowersRequest)
http.HandleFunc("/getSettings", handleSettingsGetRequest)
http.HandleFunc("/setSettings", handleSettingsSetRequest)
http.HandleFunc("/shutdown", handleShutdownRequest)
http.HandleFunc("/reboot", handleRebootRequest)
err := http.ListenAndServe(managementAddr, nil)

Wyświetl plik

@ -85,4 +85,6 @@
</div>
</div>
</div>
<a class="btn btn-warning" href="/reboot">REBOOT</a>
<a class="btn btn-danger" href="/shutdown">SHUTDOWN</a>
</div>