diff --git a/init/fedora b/init/fedora new file mode 100644 index 00000000..488027cb --- /dev/null +++ b/init/fedora @@ -0,0 +1,90 @@ +### 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 CouchPotato +# Description: starts CouchPotato +### END INIT INFO + +# Source function library. +. /etc/init.d/functions + +# Source couchpotato configuration +if [ -f /etc/sysconfig/couchpotato ]; then + . /etc/sysconfig/couchpotato +fi + +prog=couchpotato +lockfile=/var/lock/subsys/$prog + +## Edit user configuation in /etc/sysconfig/couchpotato to change +## the defaults +username=${CP_USER-couchpotato} +homedir=${CP_HOME-/opt/couchpotato} +datadir=${CP_DATA-~/.couchpotato} +pidfile=${CP_PIDFILE-/var/run/couchpotato/couchpotato.pid} +## + +pidpath=`dirname ${pidfile}` +options=" --daemon --pidfile=${pidfile} --datadir=${datadir}" + +# create PID directory if not exist and ensure the couchpotato user can write to it +if [ ! -d $pidpath ]; then + mkdir -p $pidpath + chown $username $pidpath +fi + +if [ ! -d $datadir ]; then + mkdir -p $datadir + chown $username $datadir +fi + +start() { + # Start daemon. + echo -n $"Starting $prog: " + daemon --user=${username} --pidfile=${pidfile} python ${homedir}/CouchPotato.py ${options} + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch $lockfile + return $RETVAL +} + +stop() { + echo -n $"Shutting down $prog: " + killproc -p ${pidfile} python + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && rm -f $lockfile + return $RETVAL +} + +# See how we were called. +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status $prog + ;; + restart|force-reload) + stop + start + ;; + try-restart|condrestart) + if status $prog > /dev/null; then + stop + start + fi + ;; + reload) + exit 3 + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}" + exit 2 +esac \ No newline at end of file diff --git a/init/freebsd b/init/freebsd new file mode 100644 index 00000000..c998488e --- /dev/null +++ b/init/freebsd @@ -0,0 +1,82 @@ +#!/bin/sh +# +# PROVIDE: couchpotato +# REQUIRE: sabnzbd +# KEYWORD: shutdown +# +# Add the following lines to /etc/rc.conf.local or /etc/rc.conf +# to enable this service: +# +# couchpotato_enable (bool): Set to NO by default. +# Set it to YES to enable it. +# couchpotato_user: The user account CouchPotato daemon runs as what +# you want it to be. It uses '_sabnzbd' user by +# default. Do not sets it as empty or it will run +# as root. +# couchpotato_dir: Directory where CouchPotato lives. +# Default: /usr/local/couchpotato +# couchpotato_chdir: Change to this directory before running CouchPotato. +# Default is same as couchpotato_dir. +# couchpotato_pid: The name of the pidfile to create. +# Default is couchpotato.pid in couchpotato_dir. + +. /etc/rc.subr + +name="couchpotato" +rcvar=${name}_enable + +load_rc_config ${name} + +: ${couchpotato_enable:="NO"} +: ${couchpotato_user:="_sabnzbd"} +: ${couchpotato_dir:="/usr/local/couchpotato"} +: ${couchpotato_chdir:="${couchpotato_dir}"} +: ${couchpotato_pid:="${couchpotato_dir}/couchpotato.pid"} + +WGET="/usr/local/bin/wget" # You need wget for this script to safely shutdown CouchPotato. +HOST="127.0.0.1" # Set CouchPotato address here. +PORT="8081" # Set CouchPotato port here. +CPAPI="" # Set CouchPotato API key + +status_cmd="${name}_status" +stop_cmd="${name}_stop" + +command="/usr/sbin/daemon" +command_args="-f -p ${couchpotato_pid} python ${couchpotato_dir}/couchpotato.py ${couchpotato_flags} --quiet" + +# Check for wget and refuse to start without it. +if [ ! -x "${WGET}" ]; then + warn "couchpotato not started: You need wget to safely shut down CouchPotato." + exit 1 +fi + +# Ensure user is root when running this script. +if [ `id -u` != "0" ]; then + echo "Oops, you should be root before running this!" + exit 1 +fi + +verify_couchpotato_pid() { + # Make sure the pid corresponds to the CouchPotato process. + pid=`cat ${couchpotato_pid} 2>/dev/null` + ps -p ${pid} | grep -q "python ${couchpotato_dir}/couchpotato.py" + return $? +} + +# Try to stop CouchPotato cleanly by calling shutdown over http. +couchpotato_stop() { + echo "Stopping $name" + verify_couchpotato_pid + ${WGET} -O - -q "http://${HOST}:${PORT}/${CPAPI}/app.shutdown/" >/dev/null + if [ -n "${pid}" ]; then + wait_for_pids ${pid} + echo "Stopped" + fi +} + +couchpotato_status() { + verify_couchpotato_pid && echo "$name is running as ${pid}" || echo "$name is not running" +} + +run_rc_command "$1" + diff --git a/init/solaris11 b/init/solaris11 new file mode 100644 index 00000000..defec4c1 --- /dev/null +++ b/init/solaris11 @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/init/ubuntu b/init/ubuntu new file mode 100644 index 00000000..0b3a559b --- /dev/null +++ b/init/ubuntu @@ -0,0 +1,63 @@ +#! /bin/sh + +### 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 + +############### EDIT ME ################## +# path to app +APP_PATH=/usr/local/sbin/couchpotato + +# path to python bin +DAEMON=/usr/bin/python + +# startup args +DAEMON_OPTS=" CouchPotato.py -q" + +# script name +NAME=couchpotato + +# app name +DESC=CouchPotato + +# user +RUN_AS=root + +PID_FILE=/var/run/couchpotato.pid + +############### END EDIT ME ################## + +test -x $DAEMON || exit 0 + +set -e + +case "$1" in + start) + echo "Starting $DESC" + start-stop-daemon -d $APP_PATH -c $RUN_AS --start --background --pidfile $PID_FILE --make-pidfile --exec $DAEMON -- $DAEMON_OPTS + ;; + stop) + echo "Stopping $DESC" + start-stop-daemon --stop --pidfile $PID_FILE + ;; + + restart|force-reload) + echo "Restarting $DESC" + start-stop-daemon --stop --pidfile $PID_FILE + sleep 15 + start-stop-daemon -d $APP_PATH -c $RUN_AS --start --background --pidfile $PID_FILE --make-pidfile --exec $DAEMON -- $DAEMON_OPTS + ;; + *) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart|force-reload}" >&2 + exit 1 + ;; +esac + +exit 0