# HG changeset patch # User andrewm # Date 1436985615 -3600 # Node ID a11e23f4e6af2fb8755d73af4ceebd9950384491 # Parent afc593f7469e3b71b117d80366a791158d0d0ad7 Added script options for running in a loop at startup (needs further support for stopping) and running the project in the foreground diff -r afc593f7469e -r a11e23f4e6af scripts/run_project.sh --- a/scripts/run_project.sh Wed Jul 15 19:09:18 2015 +0100 +++ b/scripts/run_project.sh Wed Jul 15 19:40:15 2015 +0100 @@ -6,27 +6,32 @@ BBB_ADDRESS="root@192.168.7.2" BBB_PATH="~/BeagleRT" COMMAND_ARGS= +RUN_IN_FOREGROUND=0 function usage { THIS_SCRIPT=`basename "$0"` - echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args]" + echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-f]" echo " This script runs a previously compiled BeagleRT project on the BeagleBone Black. The -b option changes the default path, which is otherwise $BBB_PATH. The -c option passes command-line arguments - to the BeagleRT program; enclose the argument string in quotes." + to the BeagleRT program; enclose the argument string in quotes. + The -f argument runs the project in the foreground of the current terminal, + within a screen session that can be detached later." } OPTIND=1 -while getopts "b:c:h" opt; do +while getopts "b:c:fh" opt; do case $opt in b) BBB_PATH=$OPTARG ;; c) COMMAND_ARGS=$OPTARG ;; + f) RUN_IN_FOREGROUND=1 + ;; h|\?) usage exit 1 esac @@ -35,4 +40,9 @@ shift $((OPTIND-1)) echo "Running BeagleRT..." -ssh $BBB_ADDRESS "kill -s 2 \`pidof BeagleRT\` 2>/dev/null ; sleep 0.5 ; screen -S BeagleRT -d -m $BBB_PATH/BeagleRT $COMMAND_ARGS" \ No newline at end of file +if [ $RUN_IN_FOREGROUND -eq 0 ] +then + ssh $BBB_ADDRESS "kill -s 2 \`pidof BeagleRT\` 2>/dev/null ; sleep 0.5 ; screen -S BeagleRT -d -m $BBB_PATH/BeagleRT $COMMAND_ARGS" +else + ssh -t $BBB_ADDRESS "kill -s 2 \`pidof BeagleRT\` 2>/dev/null ; sleep 0.5 ; screen -S BeagleRT $BBB_PATH/BeagleRT $COMMAND_ARGS" +fi \ No newline at end of file diff -r afc593f7469e -r a11e23f4e6af scripts/set_startup.sh --- a/scripts/set_startup.sh Wed Jul 15 19:09:18 2015 +0100 +++ b/scripts/set_startup.sh Wed Jul 15 19:40:15 2015 +0100 @@ -7,6 +7,7 @@ BBB_PATH="/root/BeagleRT" ENABLE_STARTUP=1 COMMAND_ARGS= +RUN_IN_LOOP=0 # This path is hard-coded in the BeagleRT image at present. BBB_STARTUP_SCRIPT="/root/BeagleRT_startup.sh" @@ -14,19 +15,21 @@ function usage { THIS_SCRIPT=`basename "$0"` - echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-n]" + echo "Usage: $THIS_SCRIPT [-b path-on-beaglebone] [-c command-line-args] [-n] [-l]" echo " This script enables (by default) or disables running the BeagleRT project at startup. The -n option disables auto-startup, otherwise auto-startup is enabled. The -b option changes the default path, which is otherwise $BBB_PATH. The -c option passes command-line arguments to - the BeagleRT program; enclose the argument string in quotes." + the BeagleRT program; enclose the argument string in quotes. + The -l option runs the BeagleRT program in a loop, restarting + automatically in the event of a crash." } OPTIND=1 -while getopts "b:c:nh" opt; do +while getopts "b:c:nlh" opt; do case $opt in b) BBB_PATH=$OPTARG ;; @@ -34,6 +37,8 @@ ;; n) ENABLE_STARTUP=0 ;; + l) RUN_IN_LOOP=1 + ;; h|\?) usage exit 1 esac @@ -53,12 +58,19 @@ else echo "Enabling BeagleRT at startup..." + + SCRIPT_PRERUN= + SCRIPT_POSTRUN= + if [ $RUN_IN_LOOP -ne 0 ] ; then + SCRIPT_PRERUN="bash -c \\\"while true ; do" + SCRIPT_POSTRUN=" ; done \\\" " + fi ssh $BBB_ADDRESS "echo \"#!/bin/sh # # This file is autogenerated by BeagleRT. Do not edit! echo Running BeagleRT... -screen -S BeagleRT -d -m $BBB_PATH/BeagleRT $COMMAND_ARGS\" > $BBB_STARTUP_SCRIPT" +screen -S BeagleRT -d -m $SCRIPT_PRERUN $BBB_PATH/BeagleRT $COMMAND_ARGS $SCRIPT_POSTRUN\" > $BBB_STARTUP_SCRIPT" fi \ No newline at end of file