pull/248/head
root 2016-02-16 13:19:47 +00:00
commit 9857f36023
12 zmienionych plików z 156 dodań i 25 usunięć

Wyświetl plik

@ -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 "$?"

Wyświetl plik

@ -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)

Wyświetl plik

@ -17,6 +17,7 @@ import (
"io"
"log"
"net/http"
"os"
"strings"
"syscall"
"time"
@ -248,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)
@ -262,6 +267,33 @@ 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.
file, handler, err := r.FormFile("update_file")
if err != nil {
log.Printf("Update failed from %s (%s).\n", r.RemoteAddr, err.Error())
return
}
defer file.Close()
updateFile := fmt.Sprintf("/root/%s", handler.Filename)
f, err := os.OpenFile(updateFile, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
log.Printf("Update failed from %s (%s).\n", r.RemoteAddr, err.Error())
return
}
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) {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
@ -269,7 +301,7 @@ func setNoCache(w http.ResponseWriter) {
}
func defaultServer(w http.ResponseWriter, r *http.Request) {
setNoCache(w)
// setNoCache(w)
http.FileServer(http.Dir("/var/www")).ServeHTTP(w, r)
}
@ -313,6 +345,7 @@ func managementInterface() {
http.HandleFunc("/shutdown", handleShutdownRequest)
http.HandleFunc("/reboot", handleRebootRequest)
http.HandleFunc("/getClients", handleClientsGetRequest)
http.HandleFunc("/updateUpload", handleUpdatePostRequest)
err := http.ListenAndServe(managementAddr, nil)

Wyświetl plik

@ -82,6 +82,17 @@ func getDHCPLeases() (map[string]string, error) {
hostname := strings.TrimRight(strings.TrimLeft(strings.Join(spaced[3:], " "), "\""), "\";")
ret[block_ip] = hostname
open_block = false
} else if open_block && len(spaced) >= 4 && spaced[2] == "ends" {
end_time := spaced[4] + " " + strings.TrimRight(spaced[5], ";")
// Mon Jan 2 15:04:05 -0700 MST 2006.
// 2016/02/02 00:39:59.
t, err := time.Parse("2006/01/02 15:04:05", end_time) // "In the absence of a time zone indicator, Parse returns a time in UTC."
if err == nil && t.Before(time.Now()) {
log.Printf("lease expired for %s (%s) - skipping.\n", block_ip, end_time)
open_block = false
delete(ret, block_ip)
block_ip = ""
}
} else if open_block && strings.HasPrefix(spaced[0], "}") { // No hostname.
open_block = false
ret[block_ip] = ""
@ -215,7 +226,7 @@ func refreshConnectedClients() {
}
func messageQueueSender() {
secondTimer := time.NewTicker(5 * time.Second)
secondTimer := time.NewTicker(15 * time.Second)
queueTimer := time.NewTicker(100 * time.Millisecond)
var lastQueueTimeChange time.Time // Reevaluate send frequency every 5 seconds.

Wyświetl plik

@ -968,7 +968,7 @@ func gpsSerialReader() {
for scanner.Scan() && globalStatus.GPS_connected && globalSettings.GPS_Enabled {
i++
if i%100 == 0 {
fmt.Printf("gpsSerialReader() scanner loop iteration i=%d\n", i) // debug monitor
log.Printf("gpsSerialReader() scanner loop iteration i=%d\n", i) // debug monitor
}
s := scanner.Text()
@ -981,7 +981,7 @@ func gpsSerialReader() {
log.Printf("reading standard input: %s\n", err.Error())
}
fmt.Printf("Exiting gpsSerialReader() after i=%d loops\n", i) // debug monitor
log.Printf("Exiting gpsSerialReader() after i=%d loops\n", i) // debug monitor
globalStatus.GPS_connected = false
readyToInitGPS = true // TO-DO: replace with channel control to terminate goroutine when complete
return

Wyświetl plik

@ -340,7 +340,7 @@ func sdrWatcher() {
// cleanup if necessary
if count < 1 || (!globalSettings.UAT_Enabled && !globalSettings.ES_Enabled) {
log.Println("count == 0, doing cleanup if necessary...")
// log.Println("count == 0, doing cleanup if necessary...")
if UATDev != nil {
UATDev.shutdown()
UATDev = nil

Wyświetl plik

@ -20,12 +20,21 @@ cp libdump978.so work/bin/
cp linux-mpu9150/libimu.so work/bin/
cp init.d-stratux work/bin/
cp dump1090/dump1090 work/bin/
cp -r web work/bin/
#TODO: librtlsdr.
cd work/
cat ../selfupdate/update_header.sh >update.sh
echo "stratuxVersion=${stratuxVersion}" >>update.sh
echo "stratuxBuild=${stratuxBuild}" >>update.sh
find bin/ -type d | sed -e 's/^bin\///' | grep -v '^$' | while read dn; do
echo "mkdir -p $dn" >>update.sh
done
find bin/ -type f | while read fn; do
echo -n "packaging $fn... "
UPFN=`echo $fn | cut -d/ -f2`
UPFN=`echo $fn | sed -e 's/^bin\///'`
echo "cat >${UPFN}.b64 <<__EOF__" >>update.sh
gzip -c $fn | base64 >>update.sh
echo "__EOF__" >>update.sh
@ -37,7 +46,7 @@ cat ../selfupdate/update_footer.sh >>update.sh
chmod +x update.sh
OUTF="update-${stratuxVersion}.sh"
OUTF="update-${stratuxVersion}-${stratuxBuild:0:10}.sh"
mv update.sh $OUTF

Wyświetl plik

@ -1,12 +1,15 @@
cp -f gen_gdl90 /usr/bin/gen_gdl90
cp -f libdump978.so /usr/lib/libdump978.so
cp -f linux-mpu9150/libimu.so /usr/lib/libimu.so
cp -f libimu.so /usr/lib/libimu.so
#Startup script.
# Startup script.
cp -f init.d-stratux /etc/init.d/stratux
chmod 755 /etc/init.d/stratux
ln -s /etc/init.d/stratux /etc/rc2.d/S01stratux
ln -s /etc/init.d/stratux /etc/rc6.d/K01stratux
ln -fs /etc/init.d/stratux /etc/rc2.d/S01stratux
ln -fs /etc/init.d/stratux /etc/rc6.d/K01stratux
cp -f dump1090 /usr/bin/
# Web files install.
cd web/ && make stratuxBuild=${stratuxBuild}

Wyświetl plik

@ -32,6 +32,10 @@ func main() {
x := strings.Split(buf, ",")
if len(x) < 2 {
continue
}
uatMsg, err := uatparse.New(x[1])
if err != nil {
// fmt.Printf("err %s\n", err.Error())

Wyświetl plik

@ -1,3 +1,7 @@
ifeq ($(statuxBuild),)
stratuxBuild=`git log -n 1 --pretty=%H`
endif
all:
mkdir -p /var/www
mkdir -p /var/www/css
@ -30,4 +34,4 @@ all:
cp index.html /var/www
cp stratux.appcache /var/www
# Mark the manifest with the git hash.
echo "# Stratux build: " `git log -n 1 --pretty=%H` >>/var/www/stratux.appcache
echo "# Stratux build: " ${stratuxBuild} >>/var/www/stratux.appcache

Wyświetl plik

@ -110,12 +110,29 @@ function SettingsCtrl($rootScope, $scope, $state, $http) {
}
};
$scope.postShutdown = function () {
$http.post('/shutdown');
};
$scope.postShutdown = function () {
$http.post('/shutdown');
};
$scope.postReboot = function () {
$http.post('/reboot');
};
$scope.postReboot = function () {
$http.post('/reboot');
};
$scope.uploadFile = function(files) {
var fd = new FormData();
//Take the first selected file
fd.append("update_file", files[0]);
$http.post("/updateUpload", fd, {
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
}).success(function (data) {
alert("success. wait 60 seconds and refresh home page to verify new version.");
window.location.replace("/");
}).error(function (data) {
alert("error");
});
};
};

Wyświetl plik

@ -80,14 +80,14 @@
</div>
</div>
</div>
<div class="panel-group col-sm-6">
<div class="panel-group col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Shutdown</div>
<div class="panel-body">
<div class="form-group">
<div class="col-xs-5">
<button ui-turn-on="modalShutdown">Shutdown</button>
</div>
<button ui-turn-on="modalShutdown">Shutdown</button>
</div>
</div>
</div>
</div>
@ -104,6 +104,21 @@
</div>
</div>
</div>
<!-- Upload. Temporary. -->
<div class="panel-group col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Update</div>
<div class="panel-body">
<div class="form-group">
<div class="col-xs-5">
<input class="col-xs-7" type="file" name="update_file" onChange="angular.element(this).scope().uploadFile(this.files)"/>
</div>
</div>
</div>
</div>
</div>
</div>