From 02bf2251d8d191fc678f72b7fafc98d184546c70 Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Mon, 15 Feb 2016 17:48:33 -0500 Subject: [PATCH] Rough update process - startup script looks for update file, executes it, reboots. --- init.d-stratux | 10 ++++++++++ main/gen_gdl90.go | 31 ++++++++++++++++++++++++++++--- main/managementinterface.go | 13 ++++++++++++- web/plates/js/settings.js | 3 ++- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/init.d-stratux b/init.d-stratux index 99ba803c..e2889e65 100755 --- a/init.d-stratux +++ b/init.d-stratux @@ -30,6 +30,16 @@ case "$1" in start) log_daemon_msg "Starting $DESC" "$NAME" echo powersave >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor + # Check if we need to run an update. + UPDATE_SCRIPT=`ls -1t /root/update*.sh | head -1` + if [ -n "$UPDATE_SCRIPT" ] ; then + # Execute the script, remove it, then reboot. + echo + echo "Running update script ${UPDATE_SCRIPT}..." + sh ${UPDATE_SCRIPT} + rm -f $UPDATE_SCRIPT + reboot + fi start-stop-daemon --start --background --oknodo --quiet --exec "$DAEMON_SBIN" \ --pidfile "$PIDFILE" --make-pidfile -- $DAEMON_OPTS >/dev/null log_end_msg "$?" diff --git a/main/gen_gdl90.go b/main/gen_gdl90.go index 9a1c19a8..69738149 100644 --- a/main/gen_gdl90.go +++ b/main/gen_gdl90.go @@ -1236,16 +1236,41 @@ func openReplayFile(fn string) ReadCloser { var stratuxClock *monotonic var sigs = make(chan os.Signal, 1) // Signal catch channel (shutdown). +// Close replay log file handles. +func closeReplayLogs() { + if uatReplayWriter != nil { + uatReplayWriter.Close() + } + if esReplayWriter != nil { + esReplayWriter.Close() + } + if gpsReplayWriter != nil { + gpsReplayWriter.Close() + } + if ahrsReplayWriter != nil { + ahrsReplayWriter.Close() + } + if dump1090ReplayWriter != nil { + dump1090ReplayWriter.Close() + } + +} + // Graceful shutdown. -func signalWatcher() { - sig := <-sigs - log.Printf("signal caught: %s - shutting down.\n", sig.String()) +func gracefulShutdown() { // Shut down SDRs. sdrKill() //TODO: Any other graceful shutdown functions. + closeReplayLogs() os.Exit(1) } +func signalWatcher() { + sig := <-sigs + log.Printf("signal caught: %s - shutting down.\n", sig.String()) + gracefulShutdown() +} + func main() { // Catch signals for graceful shutdown. signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) diff --git a/main/managementinterface.go b/main/managementinterface.go index f97d783c..bfe7cf95 100644 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -249,11 +249,15 @@ func handleShutdownRequest(w http.ResponseWriter, r *http.Request) { syscall.Reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF) } -func handleRebootRequest(w http.ResponseWriter, r *http.Request) { +func doReboot() { syscall.Sync() syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART) } +func handleRebootRequest(w http.ResponseWriter, r *http.Request) { + doReboot() +} + // AJAX call - /getClients. Responds with all connected clients. func handleClientsGetRequest(w http.ResponseWriter, r *http.Request) { setNoCache(w) @@ -263,6 +267,11 @@ func handleClientsGetRequest(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "%s\n", clientsJSON) } +func delayReboot() { + time.Sleep(1 * time.Second) + doReboot() +} + // Upload an update file. func handleUpdatePostRequest(w http.ResponseWriter, r *http.Request) { r.ParseMultipartForm(1024 * 1024 * 32) // ~32MB update. @@ -281,6 +290,8 @@ func handleUpdatePostRequest(w http.ResponseWriter, r *http.Request) { defer f.Close() io.Copy(f, file) log.Printf("%s uploaded %s for update.\n", r.RemoteAddr, updateFile) + // Successful update upload. Now reboot. + go delayReboot() } func setNoCache(w http.ResponseWriter) { diff --git a/web/plates/js/settings.js b/web/plates/js/settings.js index 2818e402..bb2166dd 100755 --- a/web/plates/js/settings.js +++ b/web/plates/js/settings.js @@ -128,7 +128,8 @@ function SettingsCtrl($rootScope, $scope, $state, $http) { headers: {'Content-Type': undefined }, transformRequest: angular.identity }).success(function (data) { - alert("success"); + alert("success. wait 60 seconds and refresh home page to verify new version."); + window.location.replace("/"); }).error(function (data) { alert("error"); });