From f583f4c63ed7279d540fb73c38dbacca2ebc497e Mon Sep 17 00:00:00 2001 From: mutto233 <39921339+mutto233@users.noreply.github.com> Date: Mon, 2 Jul 2018 00:51:28 -0400 Subject: [PATCH] startstop.sh fixes Fixed interpreter error in startstop.sh --- channel-dir/startstop.sh | 180 +++++++++++++++++++-------------------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/channel-dir/startstop.sh b/channel-dir/startstop.sh index 82756ed..1bac057 100644 --- a/channel-dir/startstop.sh +++ b/channel-dir/startstop.sh @@ -1,91 +1,91 @@ -#!/bin/bash - -# file: startstop.sh - -#---- -# Simple script to start / stop a python script in the background. -#---- - -#---- -# To Use: -# Just run: "./startstop.sh". If the process is running it will stop it or it will start it if not. -#---- - -#----BEGIN EDITABLE VARS---- - -SCRIPT_TO_EXECUTE_PLUS_ARGS='PseudoChannel.py -m -r' - -OUTPUT_PID_FILE=running.pid - -OUTPUT_PID_PATH=. - -PYTHON_TO_USE="$(which python)" - -# If using 'virtualenv' with python, specify the local virtualenv dir. -VIRTUAL_ENV_DIR="env" - -#----END EDITABLE VARS------- - -# If virtualenv specified & exists, using that version of python instead. -if [ -d "$VIRTUAL_ENV_DIR" ]; then - - PYTHON_TO_USE="$VIRTUAL_ENV_DIR/bin/python" - -fi - -# If the .pid file doesn't exist (let's assume no processes are running)... -if [ ! -e "$OUTPUT_PID_PATH/$OUTPUT_PID_FILE" ]; then - - # If the running.pid file doesn't exists, create it, start PseudoChannel.py and add the PID to it. - "$PYTHON_TO_USE" ./$SCRIPT_TO_EXECUTE_PLUS_ARGS > /dev/null 2>&1 & echo $! > "$OUTPUT_PID_PATH/$OUTPUT_PID_FILE" - - echo "Started $SCRIPT_TO_EXECUTE_PLUS_ARGS @ Process: $!" - - sleep .7 - - echo "Created $OUTPUT_PID_FILE file in $OUTPUT_PID_PATH dir" - -else - - # If the running.pid exists, read it & try to kill the process if it exists, then delete it. - the_pid=$(<$OUTPUT_PID_PATH/$OUTPUT_PID_FILE) - - rm "$OUTPUT_PID_PATH/$OUTPUT_PID_FILE" - - echo "Deleted $OUTPUT_PID_FILE file in $OUTPUT_PID_PATH dir" - - echo "kill: $the_pid" - - kill "$the_pid" - - COUNTER=1 - - while [ -e /proc/$the_pid ] - - do - - echo "$SCRIPT_TO_EXECUTE_PLUS_ARGS @: $the_pid is still running" - - sleep .7 - - COUNTER=$[$COUNTER +1] - - if [ $COUNTER -eq 20 ]; then - - kill -9 "$the_pid" - - fi - - if [ $COUNTER -eq 40 ]; then - - exit 1 - - fi - - done - - echo "$SCRIPT_TO_EXECUTE_PLUS_ARGS @: $the_pid has finished" - -fi - +#!/bin/bash + +# file: startstop.sh + +#---- +# Simple script to start / stop a python script in the background. +#---- + +#---- +# To Use: +# Just run: "./startstop.sh". If the process is running it will stop it or it will start it if not. +#---- + +#----BEGIN EDITABLE VARS---- + +SCRIPT_TO_EXECUTE_PLUS_ARGS='PseudoChannel.py -m -r' + +OUTPUT_PID_FILE=running.pid + +OUTPUT_PID_PATH=. + +PYTHON_TO_USE="$(which python)" + +# If using 'virtualenv' with python, specify the local virtualenv dir. +VIRTUAL_ENV_DIR="env" + +#----END EDITABLE VARS------- + +# If virtualenv specified & exists, using that version of python instead. +if [ -d "$VIRTUAL_ENV_DIR" ]; then + + PYTHON_TO_USE="$VIRTUAL_ENV_DIR/bin/python" + +fi + +# If the .pid file doesn't exist (let's assume no processes are running)... +if [ ! -e "$OUTPUT_PID_PATH/$OUTPUT_PID_FILE" ]; then + + # If the running.pid file doesn't exists, create it, start PseudoChannel.py and add the PID to it. + "$PYTHON_TO_USE" ./$SCRIPT_TO_EXECUTE_PLUS_ARGS > /dev/null 2>&1 & echo $! > "$OUTPUT_PID_PATH/$OUTPUT_PID_FILE" + + echo "Started $SCRIPT_TO_EXECUTE_PLUS_ARGS @ Process: $!" + + sleep .7 + + echo "Created $OUTPUT_PID_FILE file in $OUTPUT_PID_PATH dir" + +else + + # If the running.pid exists, read it & try to kill the process if it exists, then delete it. + the_pid=$(<$OUTPUT_PID_PATH/$OUTPUT_PID_FILE) + + rm "$OUTPUT_PID_PATH/$OUTPUT_PID_FILE" + + echo "Deleted $OUTPUT_PID_FILE file in $OUTPUT_PID_PATH dir" + + echo "kill: $the_pid" + + kill "$the_pid" + + COUNTER=1 + + while [ -e /proc/$the_pid ] + + do + + echo "$SCRIPT_TO_EXECUTE_PLUS_ARGS @: $the_pid is still running" + + sleep .7 + + COUNTER=$[$COUNTER +1] + + if [ $COUNTER -eq 20 ]; then + + kill -9 "$the_pid" + + fi + + if [ $COUNTER -eq 40 ]; then + + exit 1 + + fi + + done + + echo "$SCRIPT_TO_EXECUTE_PLUS_ARGS @: $the_pid has finished" + +fi + exit 0 \ No newline at end of file