Skip to content

Commit

Permalink
Rough update process - startup script looks for update file, executes…
Browse files Browse the repository at this point in the history
… it, reboots.
  • Loading branch information
cyoung committed Feb 15, 2016
1 parent f63f70d commit 02bf225
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
10 changes: 10 additions & 0 deletions init.d-stratux
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$?"
Expand Down
31 changes: 28 additions & 3 deletions main/gen_gdl90.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion main/managementinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion web/plates/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down

0 comments on commit 02bf225

Please sign in to comment.