#!/bin/sh # # PROVIDE: couchpotato # REQUIRE: DAEMON 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 Couch Potato 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 Couch Potato lives. # Default: /usr/local/couchpotato # couchpotato_chdir: Change to this directory before running Couch Potato. # Default is same as couchpotato_dir. # couchpotato_pid: The name of the pidfile to create. # Default is couchpotato.pid in couchpotato_dir. PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
WGET="/usr/local/bin/wget"# You need wget for this script to safely shutdown Couch Potato. HOST="127.0.0.1"# Set Couch Potato address here. PORT="5000"# Set Couch Potato port here. SBUSR=""# Set Couch Potato username (if you use one) here. SBPWD=""# Set Couch Potato password (if you use one) here.
# Check for wget and refuse to start without it. if [ ! -x "${WGET}" ]; then warn "Couchpotato not started: You need wget to safely shut down Couch Potato." 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 Couch Potato process. pid=`cat${couchpotato_pid} 2>/dev/null` ps -p ${pid} | grep -q "python ${couchpotato_dir}/CouchPotato.py" return $? }
# Try to stop Couch Potato cleanly by calling shutdown over http. couchpotato_stop() { echo"Stopping $name" verify_couchpotato_pid ${WGET} -O - -q --user=${SBUSR} --password=${SBPWD}"http://${HOST}:${PORT}/home/shutdown/?pid=${pid}" >/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" }