Added startstop.sh file to easily start / stop PseudoChannel.py in the background. Also loggin support in ./pseudo-channel.log

This commit is contained in:
Justin Emter
2017-08-09 00:30:02 -07:00
parent 7ff9b6e548
commit f2b6b87b56
3 changed files with 54 additions and 1 deletions

2
.gitignore vendored
View File

@@ -9,3 +9,5 @@ old/
pseudo-channel.db
*.db-journal
env/
*.log
*.pid

View File

@@ -16,6 +16,7 @@ from plexapi.server import PlexServer
import sys
import datetime
from datetime import time
import logging
import calendar
import itertools
import argparse
@@ -56,6 +57,8 @@ class PseudoChannel():
def __init__(self):
logging.basicConfig(filename="pseudo-channel.log", level=logging.INFO)
self.db = PseudoChannelDatabase("pseudo-channel.db")
self.controller = PseudoDailyScheduleController(
@@ -1060,7 +1063,7 @@ if __name__ == '__main__':
"""
logging.info("+++++ Running PseudoChannel.py -r")
def trigger_what_should_be_playing_now():
@@ -1233,6 +1236,8 @@ if __name__ == '__main__':
if sleep_before_triggering_play_now:
logging.info("+++++ Successfully started PseudoChannel.py")
trigger_what_should_be_playing_now()
sleep_before_triggering_play_now = 0

46
startstop.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/bash
# file: startstop.sh
#----
# Simple script to start / stop PseudoChannel.py
#----
#----
# 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----
pid_file=running.pid
output_pid_path=.
python_to_use="$(which python)"
#----END EDITABLE VARS-------
if [ ! -e $output_pid_path/$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
echo "Started PseudoChannel.py @ Process: $!"
echo "Created $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
while [ -e /proc/$the_pid ]
do
echo "PseudoChannel.py @: $the_pid is still running"
sleep .6
done
echo "PseudoChannel.py @: $the_pid has finished"
fi