Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pyload daemon
#!/bin/sh
### BEGIN INIT INFO
# Provides: pyload
# Required-Start: $syslog $local_fs $network $remote_fs
# Required-Stop: $syslog $local_fs $network $remote_fs
# Should-Start: $remote_fs $named
# Should-Stop: $remote_fs $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts pyload daemon
# Description: This script runs the pyload service
### END INIT INFO
set -e
############### BEGIN EDIT ME ################
RUN_AS=nlsltz
RUN_GRP=nlsltz
APP_PATH=/usr/share/pyload
DAEMON=/usr/bin/python
PID_FILE=/var/run/pyload/pyload.pid
PID_PATH=$(dirname $PID_FILE)
NAME=pyload
DESC=pyload
configdir="/home/nlsltz/.pyload"
DAEMON_OPTS="${APP_PATH}/pyLoadCore.py --daemon --pidfile=${PID_FILE} --configdir=${configdir}"
############### END EDIT ME ##################
# Get lsb functions
. /lib/lsb/init-functions
# Create PID directory if not exist and ensure the pyload user can write to it
if [ ! -d $PID_PATH ]; then
mkdir -p $PID_PATH
chown $RUN_AS $PID_PATH
chmod 777 $PID_PATH -R
fi
if [ -e $PID_FILE ]; then
PID=`cat $PID_FILE`
if ! kill -0 $PID > /dev/null 2>&1; then
echo "Removing stale $PID_FILE"
rm $PID_FILE
fi
fi
is_running=`ps ax | grep pyLoad | awk '{ print $1 }' | wc -l`
case "$1" in
start)
if [ "$is_running" -gt 1 ]; then
echo "pyload already running..."
exit 0
fi
echo -n "Starting pyload: "
start-stop-daemon -d $APP_PATH -c $RUN_AS --start --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS > /dev/null 2>&1
sleep 1
echo "done"
;;
stop)
if [ "$is_running" -eq 1 ]; then
echo "pyload is not running (no process found)..."
exit 0
fi
echo -n "Killing pyload: "
# Trying to kill the Plex Media Server itself but also the Plug-ins
ps ax | grep py[L]oad | awk '{ print $1 }' | xargs kill -9 >/dev/null 2>&1
sleep 1
echo "done"
;;
restart)
sh $0 stop
sh $0 start
;;
status)
if [ "$is_running" -gt 1 ]; then
echo "pyload Server process running."
return 0
else
echo "It seems that pyload Server isn't running (no process found)."
return 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.