Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 46dbb59bcd
Fetching contributors…

Cannot retrieve contributors at this time

executable file 151 lines (123 sloc) 4.039 kb
#! /bin/sh
# Copyright (C) 2011- by Mar2zz <LaSi.Mar2zz@gmail.com>
# released under GPL, version 2 or later
################################################
# #
# TO CONFIGURE EDIT /etc/default/couchpotato
# #
################################################
### BEGIN INIT INFO
# Provides: CouchPotato application instance
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts instance of CouchPotato
# Description: starts instance of CouchPotato using start-stop-daemon
### END INIT INFO
# main variables
DAEMON=/usr/bin/python
SETTINGS=/etc/default/couchpotato
SETTINGS_LOADED=FALSE
DESC=CouchPotato
# only accept values from /etc/default/couchpotato
unset RUN_AS CONFIG DATADIR PORT PID_FILE
. /lib/lsb/init-functions
[ -x $DAEMON ] || {
log_warning_msg "$DESC: Can't execute daemon, aborting. See $DAEMON";
return 1; }
[ -r $SETTINGS ] || {
log_warning_msg "$DESC: Can't read settings, aborting. See $SETTINGS";
return 1; }
check_retval() {
if [ $? -eq 0 ]; then
log_end_msg 0
return 0
else
log_end_msg 1
exit 1
fi
}
load_settings() {
if [ $SETTINGS_LOADED != "TRUE" ]; then
. $SETTINGS
[ -n "$APP_PATH" ] || {
log_warning_msg "$DESC: path to $DESC not set, aborting. See $SETTINGS";
return 1; }
[ $ENABLE_DAEMON != 1 ] && {
log_warning_msg "$DESC: daemon not enabled, aborting. See $SETTINGS";
return 1; }
[ -z "$RUN_AS" ] && {
log_warning_msg "$DESC: daemon username not set, aborting. See $SETTINGS";
return 1; }
[ -z "${RUN_AS%:*}" ] && exit 1
DAEMON_OPTS="CouchPotato.py --quiet -d --nolaunch"
[ -n "$CONFIG" ] && DAEMON_OPTS="$DAEMON_OPTS --config=$CONFIG"
[ -z "$CONFIG" ] && DAEMON_OPTS="$DAEMON_OPTS --config=/home/$RUN_AS/.couchpotato/config.ini"
[ -n "$DATADIR" ] && DAEMON_OPTS="$DAEMON_OPTS --datadir=$DATADIR"
[ -z "$DATADIR" ] && DAEMON_OPTS="$DAEMON_OPTS --datadir=/home/$RUN_AS/.couchpotato"
[ -n "$PORT" ] && DAEMON_OPTS="$DAEMON_OPTS --port=$PORT"
if ! [ -n "$PID_FILE" ]; then
PID_FILE=/var/run/couchpotato/couchpotato.pid
fi
DAEMON_OPTS="$DAEMON_OPTS --pidfile=$PID_FILE"
SETTINGS_LOADED=TRUE
fi
return 0
}
load_settings || exit 0
is_running () {
# returns 1 when running, else 0.
PID=$(pgrep -f "$DAEMON_OPTS")
RET=$?
[ $RET -gt 1 ] && exit 1 || return $RET
}
handle_pid () {
PID_PATH=`dirname $PID_FILE`
[ -d $PID_PATH ] || mkdir -p $PID_PATH && chown -R $RUN_AS $PID_PATH > /dev/null || {
log_warning_msg "$DESC: Could not create $PID_FILE, aborting.";
return 1;}
}
enable_updates () {
chown -R $RUN_AS $APP_PATH > /dev/null || {
log_warning_msg "$DESC: $APP_PATH not writable for web-updates, See $SETTINGS";
return 0; }
}
start_couchpotato () {
if ! is_running; then
log_daemon_msg "Starting $DESC"
[ "$WEB_UPDATE" = 1 ] && enable_updates
handle_pid
start-stop-daemon -o -d $APP_PATH -c $RUN_AS --start --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
check_retval
else
log_success_msg "$DESC: already running (pid $PID)"
fi
}
stop_couchpotato () {
if is_running; then
log_daemon_msg "Stopping $DESC"
start-stop-daemon -o --stop --pidfile $PID_FILE --retry 15
check_retval
else
log_success_msg "$DESC: not running"
fi
}
case "$1" in
start)
start_couchpotato
;;
stop)
stop_couchpotato
;;
restart|force-reload)
stop_couchpotato
start_couchpotato
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
Jump to Line
Something went wrong with that request. Please try again.