I updated a page on David Taylor's excellent PlanePlotter wiki, detailing how to use a Mode-S Beast with a Raspberry Pi v2 and modesmixer2 for autonomous uploading to the PlanePlotter servers, as well as MLAT servicing to other Ground Stations.
http://planeplotter.pbworks.com/w/page/97777870/Using%20a%20Raspberry%20Pi%20with%20The%20Mode-S%20Beast (http://planeplotter.pbworks.com/w/page/97777870/Using%20a%20Raspberry%20Pi%20with%20The%20Mode-S%20Beast)
Regards,
Don
WD9DMP
Hello,
i have a question for the raspberry pros.
I configured my Pi using the link above. At the end it points to the automated script shown on the satsignal page to make the programs run after booting the Pi.
http://www.satsignal.eu/raspberry-pi/dump1090.html#automated-start
Quote#!/bin/bash
### BEGIN INIT INFO
#
# Provides: dump1090
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: dump1090 initscript
#
### END INIT INFO
## Fill in name of program here.
PROG="dump1090"
PROG_PATH="/home/pi/modesmixer2"
PROG_ARGS="--inSerial /dev/ttyUSB0:3000000:hardware --outServer beast:30005 --outServer msg:30003 --web 8080 --location yy.yyyy:xx.xxxx"
PIDFILE="/var/run/$PROG.pid"
PROG2="ppup1090"
PROG2_ARGS="--quiet"
PIDFILE2="/var/run/$PROG2.pid"
DELAY=5
start() {
if [ -e $PIDFILE ]; then
## Program is running, exit with error.
echo "Error! $PROG is currently running!" 1>&2
exit 1
else
## Change from /dev/null to something like /var/log/$PROG if you want to save output.
cd $PROG_PATH
./$PROG $PROG_ARGS 2>&1 >/dev/null &
echo "$PROG started, waiting $DELAY seconds..."
touch $PIDFILE
sleep $DELAY
echo "Attempting to start $PROG2..."
./$PROG2 $PROG2_ARGS 2>&1 >/dev/null &
echo "$PROG2 started"
touch $PIDFILE2
fi
}
stop() {
if [ -e $PIDFILE ]; then
## Program is running, so stop it
echo "$PROG is running"
killall $PROG2
killall $PROG
rm -f $PIDFILE2
rm -f $PIDFILE
echo "$PROG stopped"
else
## Program is not running, exit with error.
echo "Error! $PROG not started!" 1>&2
exit 1
fi
}
## Check to see if we are running as root first.
## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
case "$1" in
start)
start
exit 0
;;
stop)
stop
exit 0
;;
reload|restart|force-reload)
stop
start
exit 0
;;
**)
echo "Usage: $0 {start|stop|reload}" 1>&2
exit 1
;;
esac
#
Does anyone know what i must do to run another program from this script? it would be a java *.jar file to upload data to live-military-mode-s.eu which must be run using the "java -jar filename.jar" command. Another thing i'd like to add to the script is an automated restart after 24h since the beast loses the handshake again after a certain uptime. Is it possilbe to add an automated restart to a script like this?
So are you running that startup script at the moment?
It starts dump1090 and ppup1090. Do you need both of these or just dump1090?
What do you need to restart every 24 hours? Just the java command or the Pi?
I edited the script to start modesmixer2 instead of dump1090 since i am using a beast. I need the following things to be started by the script:
Modesmixer2 - to connect to the beast - works already
Ppup1090 - to feed to planeplotter - works too
The modes.jar - to feed to live military mode s
A auto restart for the wohle pi after 24h
The Last two things have to be included in the script. Perhaps someone knows what has to be written into it...
The restart is done using a cron job in Linux.
Look at this: http://www.adminschoice.com/crontab-quick-reference
On the pi, the command crontab -e will open an editor so you can set up your repeating task.
Something like this will reboot the pi at 0100 every day. Not very elegant since it just kills all the running applications :( and reboots. Adjust time as needed (the second number is the hours so could be 18 for 6pm}
0 1 * * * sudo reboot
For the java command, I wonder if it can be added in to the existing script. No point in reinventing it - just need to confirm what is going on.
Edit: updated with Triple7's corrections
Looking at that shell script, someone added starting up ppup1090 from the original version so why not try adding your java command as well. Add the bits in red to the existing script (I've not included all the old script here to keep it shorter - do not delete anything from script - just add!!
This might work if linux can find the "filename.jar" - give it a try. If it doesn't we need a linux expert ;)
<<existing code>>
### END INIT INFO
## Fill in name of program here.
PROG="dump1090"
PROG_PATH="/home/pi/modesmixer2"
PROG_ARGS="--inSerial /dev/ttyUSB0:3000000:hardware --outServer beast:30005 --outServer msg:30003 --web 8080 --location yy.yyyy:xx.xxxx"
PIDFILE="/var/run/$PROG.pid"
PROG2="ppup1090"
PROG2_ARGS="--quiet"
PIDFILE2="/var/run/$PROG2.pid"
PROG3="java"
PROG3_ARGS="-jar filename.jar"
PIDFILE3="/var/run/$PROG3.pid"
DELAY=5
start() {
if [ -e $PIDFILE ]; then
## Program is running, exit with error.
echo "Error! $PROG is currently running!" 1>&2
exit 1
else
## Change from /dev/null to something like /var/log/$PROG if you want to save output.
cd $PROG_PATH
./$PROG $PROG_ARGS 2>&1 >/dev/null &
echo "$PROG started, waiting $DELAY seconds..."
touch $PIDFILE
sleep $DELAY
echo "Attempting to start $PROG2..."
./$PROG2 $PROG2_ARGS 2>&1 >/dev/null &
echo "$PROG2 started", waiting $DELAY seconds...
touch $PIDFILE2
sleep $DELAY
echo "Attempting to start $PROG3..."
./$PROG3 $PROG3_ARGS 2>&1 >/dev/null &
echo "$PROG3 started"
touch $PIDFILE3
fi
}
stop() {
if [ -e $PIDFILE ]; then
## Program is running, so stop it
echo "$PROG is running"
killall $PROG3
killall $PROG2
killall $PROG
rm -f $PIDFILE3
rm -f $PIDFILE2
rm -f $PIDFILE
echo "$PROG stopped"
else
## Program is not running, exit with error.
echo "Error! $PROG not started!" 1>&2
exit 1
fi
}
<<existing code>>
Hi Ian,
Shouldn't your new code:
PROG3="java"
PROG2_ARGS="-jar filename.jar"
PIDFILE2="/var/run/$PROG3.pid"
be
PROG3="java"
PROG3_ARGS="-jar filename.jar"
PIDFILE3="/var/run/$PROG3.pid"
?
Tim
Yes - I was in a hurry since I was going out.
Thanks for doing the QC ;D
At least it made sense to you
Edit: I made the changes to my script
Ah nice!
Since i am a complete linux noob i didn't have a clue. Especially with this pid stuff. Now that i am back from my training course i will give it a try!
PID is just the process identifier - same as you in see in Windows Task Manager under the Services tab.
Linux has a way of identifying it and using that in a script to kill it when you stop the script, e.g. when you turn off the Pi.
Thank you. Got it working with a slightly different Code:
PROG3="modes.jar"
PROG3_PATH="\home\pi\livemodes"
PIDFILE3="modes.pid"
And then the code to start the prog 5 seconds after ppup1090
sleep $DELAY
echo "Attempting to start $PROG3..."
cd $PROG3_PATH
java -jar $PROG3 2>&1 >/dev/null &
echo "$PROG3 started"
touch $PIDFILE3
Now i will check the restart thing