kopia lustrzana https://github.com/cyoung/stratux
Rough update process - startup script looks for update file, executes it, reboots.
rodzic
f63f70d1d2
commit
02bf2251d8
|
@ -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 "$?"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
|
|
Ładowanie…
Reference in New Issue