You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.1 KiB
101 lines
3.1 KiB
#!/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
|
|
|
|
# Required, for some reason, to find all our binaries when starting via service.
|
|
PATH="/usr/bin:/usr/local/bin:$PATH"
|
|
|
|
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"}
|
|
: ${couchpotato_conf:="${couchpotato_dir}/data/settings.conf"}
|
|
|
|
WGET="/usr/local/bin/wget" # You need wget for this script to safely shutdown CouchPotato.
|
|
if [ -e "${couchpotato_conf}" ]; then
|
|
HOST=`grep -A14 "\[core\]" "${couchpotato_conf}"|awk -F" = " '/^host/ {print $2}'`
|
|
PORT=`grep -A14 "\[core\]" "${couchpotato_conf}"|awk -F" = " '/^port/ {print $2}'`
|
|
CPAPI=`grep -A14 "\[core\]" "${couchpotato_conf}"|awk -F" = " '/^api_key/ {print $2}'`
|
|
fi
|
|
|
|
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}"
|
|
start_cmd="${command} ${command_args}"
|
|
|
|
# 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`
|
|
if [ -n "${pid}" ]; then
|
|
ps -p ${pid} | grep -q "python ${couchpotato_dir}/CouchPotato.py"
|
|
return $?
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
# Try to stop CouchPotato cleanly by calling shutdown over http.
|
|
couchpotato_stop() {
|
|
if [ ! -e "${couchpotato_conf}" ]; then
|
|
echo "CouchPotato's settings file does not exist. Try starting CouchPotato, as this should create the file."
|
|
exit 1
|
|
fi
|
|
verify_couchpotato_pid
|
|
if [ "${?}" -eq 0 ]; then
|
|
echo "Stopping $name"
|
|
${WGET} -O - -q "http://${HOST}:${PORT}/api/${CPAPI}/app.shutdown/" >/dev/null
|
|
if [ -n "${pid}" ]; then
|
|
wait_for_pids ${pid}
|
|
echo "Stopped"
|
|
fi
|
|
else
|
|
echo "$name not running?"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
couchpotato_status() {
|
|
verify_couchpotato_pid && echo "$name is running as ${pid}" || echo "$name is not running"
|
|
}
|
|
|
|
run_rc_command "$1"
|
|
|
|
|