Keeping VRS online 24/7

Bug reports and questions about running Virtual Radar Server on Linux
Post Reply
mrbreenhd
Posts: 3
Joined: Thu Feb 01, 2018 7:58 pm

Keeping VRS online 24/7

Post by mrbreenhd » Thu Feb 01, 2018 8:02 pm

Hi All, currently having an issue the only way I can keep my VRS server on is by keeping a PuTTY client connected to it whenever I want it to access the VRS page. Is there any way I can run the VRS 100% dedicated on my Raspberry Pi B?

Thanks!

agw
Posts: 2157
Joined: Fri Feb 17, 2012 3:20 am

Re: Keeping VRS online 24/7

Post by agw » Sun Feb 04, 2018 12:22 am

This has come up before - Linux has a variety of ways of keeping a program running in the background after the shell is closed. You could try some of the suggestions here:

viewtopic.php?f=1&t=1280&p=7245

WiganPI
Posts: 2
Joined: Sun Mar 11, 2018 9:31 am
Contact:

Re: Keeping VRS online 24/7

Post by WiganPI » Mon Aug 27, 2018 2:20 pm

mrbreenhd wrote:
Thu Feb 01, 2018 8:02 pm
Hi All, currently having an issue the only way I can keep my VRS server on is by keeping a PuTTY client connected to it whenever I want it to access the VRS page. Is there any way I can run the VRS 100% dedicated on my Raspberry Pi B?

Thanks!
Had a similar issue myself and now succesfully running Mono under Screen works for me on centos 7, allows you detached and open other putty windows along with close them to run in the background.
Click Here For My VRS Install
360 Radar Contributor | ADSB Receiver Project Contributor | Opensky Network Contributor | ADSBhub Contributor

mrbreenhd
Posts: 3
Joined: Thu Feb 01, 2018 7:58 pm

Re: Keeping VRS online 24/7

Post by mrbreenhd » Tue Aug 28, 2018 1:02 pm

for some reason screen wouldn't work so I opted for tmux and works a charm

loww
Posts: 106
Joined: Sun Jun 28, 2015 10:55 am
Location: LOWW
Contact:

Re: Keeping VRS online 24/7

Post by loww » Wed Sep 05, 2018 11:38 am

Mine running on W7 and the work perfect. :D
:!: :!: :!: I search for People who want exchange VRS Data. I life near LOWW and i have a huge Coverage and multiple Receiver. :!: :!: :!:
My newest Project: http://www.publictransportforum.at/

TanerH
Posts: 7
Joined: Wed Sep 12, 2018 1:31 am

Re: Keeping VRS online 24/7

Post by TanerH » Wed Sep 12, 2018 1:45 am

Hey all,

I run VRS from this little script I made -- it's moderately-robust, but if you have a really weird setup, it might not work for you.
You can just call this something like "run_vrs.sh", and then invoke it as:

Code: Select all

./run_vrs.sh &
Here's the script. Make sure you edit "VRSPATH", "LOG" and "MONOBIN" if they differ for you.
VRSPATH is where the VirtualRadar.exe lives.

Code: Select all

#!/bin/bash

VRSPATH="/home/adsb/vrs"
LOG="/home/adsb/logs/VRS.log"
MONOBIN="/usr/bin/mono"


VRSEXEC="$MONOBIN VirtualRadar.exe -nogui"

SLEEPTIME=2
FAIL_SLEEP=60

MIN_RUN_TIME=30

touch $LOG

if [ ! -f $LOG ]; then
        echo "Something Bad Happening - can't find/use $LOG for logging, please fix"
        exit -1
fi


if [ ! -d $VRSPATH ]; then
        echo "Sorry, $VRSPATH doesn't exist or isn't a directory, bailing out..."
        exit -1
fi

if [ ! -x $MONOBIN ]; then
        echo "Sorry, mono at location $MONOBIN doesn't exist or isn't executable, bailing out..."
        exit -1
fi

while true; do
        echo "`date` :: Starting VRS launch loop..." >> $LOG 2>&1
        VRS_START=`date +%s`
        cd $VRSPATH
        echo "`date` :: Starting [$VRSEXEC]..." >> $LOG 2>&1
        $VRSEXEC >> $LOG 2>&1
        RV=$?
        VRS_END=`date +%s`
        VRS_TIME=$(($VRS_END-$VRS_START))
        echo "`date` :: VRS exited with [$RV].  Sleeping $SLEEPTIME seconds..." >> $LOG 2>&1
        sleep $SLEEPTIME
        if [ $VRS_TIME -lt $MIN_RUN_TIME ]; then
                echo "`date` :: Exited quickly (less than $MIN_RUN_TIME seconds), waiting a little more ($FAIL_SLEEP sec)..." >> $LOG 2>&1
                sleep $FAIL_SLEEP
        fi
done
Since this script redirects all output into a log file, it should survive you logging out.

You can try invoking this with "nohup" before the script name, but that may or may not matter.

Installing 'screen' or 'tmux' and running it from within that is probably a better bet (but will not auto-start at boot).

I can see about editing this script so that it's safe to run from rc.local or even from cron, if people are interested enough.

-Taner

TanerH
Posts: 7
Joined: Wed Sep 12, 2018 1:31 am

Re: Keeping VRS online 24/7

Post by TanerH » Sat Sep 15, 2018 6:01 am

Ok, I added the ability for this to just get run from cron, perhaps every 5 minutes, and it will exit silently if it's already running. You'd want to add a line like this to whatever user's crontab you run this as (run 'crontab -e' as that user):

Code: Select all

*/5 * * * * /home/adsb/cron/run_vrs.sh
I tried to make it fairly-robust and fairly-foolproof, but I'm sure you can break it if you try :)

PLEASE make sure you edit the first three variables to suit your environment (VRSPATH, LOGDIR, MONOBIN). You may also need/want to edit the "VRSEXEC" line if you use different parameters.

Code: Select all

#!/bin/bash

VRSPATH="/home/adsb/vrs"
LOGDIR="/home/adsb/cron/data"
MONOBIN="/usr/bin/mono"

LOG="${LOGDIR}/VRS.log"
PIDFILE="${LOGDIR}/run_vrs.pid"

VRSEXEC="$MONOBIN VirtualRadar.exe -nogui"

SLEEPTIME=2
FAIL_SLEEP=60

MIN_RUN_TIME=30

T="/usr/bin/tee -a $LOG"

PID=$$

if [ ! -d $LOGDIR ]; then
        if [ -e $LOGDIR ]; then
                echo "FATAL - $LOGDIR exists but is not a directory"
                exit -1
        fi
        echo "$LOGDIR doesn't seem to exist, attempting to create...."
        mkdir -p $LOGDIR
        RV=$?
        if [ $RV -ne 0 ]; then
                echo "FATAL - couldn't create directory $LOGDIR (error $RV)"
                exit -1
        fi
fi

# Can we poke the log file?
touch $LOG

if [ ! -f $LOG ]; then
        echo "Something Bad Happening - can't find/use $LOG for logging, please fix"
        exit -1
fi

# *** At this point, the logfile should work, so use it when appropriate (non-fatal)


if [ -f $PIDFILE ]; then
        OLD_PID=`cat $PIDFILE`
        if [ x"$OLD_PID" == "x" ]; then
                echo "PID file $PIDFILE is empty - skipping check..." >> $LOG
        else
                KILL=`kill -0 $OLD_PID 2>&1`
                RV=$?
                if [ $RV -eq 0 ]; then
                        # Already running, exit quietly
                        exit
                fi
                echo "`date` :: PID $OLD_PID from pidfile isn't running..." >> $LOG 2>&1
        fi
fi

echo $PID > $PIDFILE

# Last sanity check, in case it got started by hand...
PS_SCAN=`ps -ef | grep VirtualRadar.exe | grep mono | grep -v grep`
RV=$?
if [ $RV -ne 1 ]; then
        # Oops, we found something running!

        echo "Weirdness - found something running:" | $T
        echo $PS_SCAN | $T
        echo "Aborting..." | $T

        exit -1
fi

# Sanity here
touch $PIDFILE
if [ ! -f $PIDFILE ]; then
        echo "Something Bad Happening - can't create PID file $PIDFILE, please fix" | $T
        exit -1
fi

if [ ! -d $VRSPATH ]; then
        echo "Sorry, $VRSPATH doesn't exist or isn't a directory, bailing out..." | $T
        exit -1
fi

if [ ! -x $MONOBIN ]; then
        echo "Sorry, mono at location $MONOBIN doesn't exist or isn't executable, bailing out..." | $T
        exit -1
fi

while true; do
        echo "`date` :: Starting VRS launch loop..." >> $LOG 2>&1
        VRS_START=`date +%s`
        cd $VRSPATH
        echo "`date` :: Starting [$VRSEXEC]..." >> $LOG 2>&1
        $VRSEXEC 2>&1  >> $LOG
        RV=$?
        VRS_END=`date +%s`
        VRS_TIME=$(($VRS_END-$VRS_START))
        echo "`date` :: VRS exited with [$RV].  Sleeping $SLEEPTIME seconds..." >> $LOG 2>&1
        sleep $SLEEPTIME
        if [ $VRS_TIME -lt $MIN_RUN_TIME ]; then
                echo "`date` :: Exited quickly (less than $MIN_RUN_TIME seconds), waiting a little more ($FAIL_SLEEP sec)..." >> $LOG 2>&1
                sleep $FAIL_SLEEP
        fi
done

Post Reply