Updates to scripts.

This commit is contained in:
Justin Emter
2017-08-13 11:48:29 -07:00
parent 8056c4b9ad
commit c903a1c6d7
3 changed files with 80 additions and 29 deletions

View File

@@ -13,35 +13,57 @@
#----BEGIN EDITABLE VARS----
pid_file=running.pid
SCRIPT_TO_EXECUTE_PLUS_ARGS='PseudoChannel.py -m -r'
output_pid_path=.
OUTPUT_PID_FILE=running.pid
python_to_use="$(which python)"
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 [ ! -e $output_pid_path/$pid_file ]; then
if [ -d "$VIRTUAL_ENV_DIR" ]; then
PYTHON_TO_USE="$VIRTUAL_ENV_DIR/bin/python"
fi
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.
nohup $python_to_use ./PseudoChannel.py -m -r > /dev/null 2>&1 & echo $! > $output_pid_path/$pid_file
"$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: $!"
echo "Started PseudoChannel.py @ Process: $!"
sleep .7
echo "Created $pid_file file in $output_pid_path dir"
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/$pid_file)
rm $output_pid_path/$pid_file
echo "Deleted $pid_file file in $output_pid_path dir"
kill $the_pid
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"
kill "$the_pid"
while [ -e /proc/$the_pid ]
do
echo "PseudoChannel.py @: $the_pid is still running"
echo "$SCRIPT_TO_EXECUTE_PLUS_ARGS @: $the_pid is still running"
sleep .7
done
echo "PseudoChannel.py @: $the_pid has finished"
echo "$SCRIPT_TO_EXECUTE_PLUS_ARGS @: $the_pid has finished"
fi