From 3089cd5a3f7e95e986963e2e9ef4dbc74e4f5906 Mon Sep 17 00:00:00 2001 From: Brad Ward Date: Sat, 19 Dec 2015 15:18:00 -0600 Subject: [PATCH 1/3] Shutdown/Reboot Added methods to shutdown and reboot the pi via syscalls --- main/managementinterface.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main/managementinterface.go b/main/managementinterface.go index 6aab6cba..1d237067 100644 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -10,6 +10,7 @@ import ( "log" "net/http" "time" + "syscall" ) type SettingMessage struct { @@ -228,6 +229,20 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) { } } +func handleShutdownRequest(w http.ResponseWriter, r *http.Request) { + const LINUX_REBOOT_CMD_POWER_OFF= 0x4321FEDC + syscall.Sync() + syscall.Reboot(LINUX_REBOOT_CMD_POWER_OFF) +} + + +func handleRebootRequest(w http.ResponseWriter, r *http.Request) { + const LINUX_REBOOT_CMD_RESTART = 0x01234567 + syscall.Sync() + syscall.Reboot(LINUX_REBOOT_CMD_RESTART) +} + + func managementInterface() { weatherUpdate = NewUIBroadcaster() trafficUpdate = NewUIBroadcaster() @@ -264,6 +279,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) From ee7804d1240f90b0e7be08964c9b246e89b15448 Mon Sep 17 00:00:00 2001 From: Brad Ward Date: Sat, 19 Dec 2015 15:21:19 -0600 Subject: [PATCH 2/3] Added shutdown/reboot feature Added shutdown and reboot buttons to the status screen. --- web/plates/status.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/plates/status.html b/web/plates/status.html index e16f42ed..d1a03c07 100755 --- a/web/plates/status.html +++ b/web/plates/status.html @@ -85,4 +85,6 @@ + REBOOT + SHUTDOWN From 1c9a3a2ce2c511952fcc60b95bf961356e4da17e Mon Sep 17 00:00:00 2001 From: Brad Ward Date: Sun, 20 Dec 2015 00:56:36 +0000 Subject: [PATCH 3/3] Removed local constants in favor of using syscalls already defined exported constants --- main/managementinterface.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/main/managementinterface.go b/main/managementinterface.go index 1d237067..0e71e7eb 100644 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -219,7 +219,7 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) { log.Printf("handleSettingsSetRequest:json: unrecognized key:%s\n", key) } } - saveSettings() + saveSettings() } } @@ -230,16 +230,14 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) { } func handleShutdownRequest(w http.ResponseWriter, r *http.Request) { - const LINUX_REBOOT_CMD_POWER_OFF= 0x4321FEDC syscall.Sync() - syscall.Reboot(LINUX_REBOOT_CMD_POWER_OFF) + syscall.Reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF) } func handleRebootRequest(w http.ResponseWriter, r *http.Request) { - const LINUX_REBOOT_CMD_RESTART = 0x01234567 syscall.Sync() - syscall.Reboot(LINUX_REBOOT_CMD_RESTART) + syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART) }