Redo FreeBSD init script completely.
Use rc.subr functions and proper rc.conf variables.
This commit is contained in:
Executable → Regular
+32
-76
@@ -1,93 +1,49 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# PROVIDE: couchpotato
|
# PROVIDE: couchpotato
|
||||||
# REQUIRE: sabnzbd
|
# REQUIRE: DAEMON sabnzb transmission
|
||||||
# KEYWORD: shutdown
|
# KEYWORD: shutdown
|
||||||
#
|
|
||||||
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
|
# Add the following lines to /etc/rc.conf to enable couchpotato:
|
||||||
# to enable this service:
|
# couchpotato_enable: Set to NO by default. Set it to YES to enable it.
|
||||||
#
|
# couchpotato_user: The user account CouchPotato daemon runs as what
|
||||||
# couchpotato_enable (bool): Set to NO by default.
|
# you want it to be.
|
||||||
# Set it to YES to enable it.
|
# couchpotato_dir: Directory where CouchPotato lives.
|
||||||
# couchpotato_user: The user account CouchPotato daemon runs as what
|
# Default: /usr/local/CouchPotatoServer
|
||||||
# you want it to be. It uses '_sabnzbd' user by
|
# couchpotato_datadir: Directory where CouchPotato user data lives.
|
||||||
# default. Do not sets it as empty or it will run
|
# Default: $couchpotato_dir/data
|
||||||
# as root.
|
# couchpotato_conf: Directory where CouchPotato user data lives.
|
||||||
# couchpotato_dir: Directory where CouchPotato lives.
|
# Default: $couchpotato_datadir/settings.conf
|
||||||
# Default: /usr/local/couchpotato
|
# couchpotato_pid: Full path to PID file.
|
||||||
# couchpotato_chdir: Change to this directory before running CouchPotato.
|
# Default: $couchpotato_datadir/couchpotato.pid
|
||||||
# Default is same as couchpotato_dir.
|
# couchpotato_flags: Set additonal flags as needed.
|
||||||
# couchpotato_pid: The name of the pidfile to create.
|
|
||||||
# Default is couchpotato.pid in couchpotato_dir.
|
|
||||||
|
|
||||||
. /etc/rc.subr
|
. /etc/rc.subr
|
||||||
|
|
||||||
name="couchpotato"
|
name="couchpotato"
|
||||||
rcvar=${name}_enable
|
rcvar=couchpotato_enable
|
||||||
|
|
||||||
load_rc_config ${name}
|
load_rc_config ${name}
|
||||||
|
|
||||||
: ${couchpotato_enable:="NO"}
|
: ${couchpotato_enable:=NO}
|
||||||
: ${couchpotato_user:="_sabnzbd"}
|
: ${couchpotato_user:=} #default is root
|
||||||
: ${couchpotato_dir:="/usr/local/couchpotato"}
|
: ${couchpotato_dir:=/usr/local/CouchPotatoServer}
|
||||||
: ${couchpotato_chdir:="${couchpotato_dir}"}
|
: ${couchpotato_datadir:=${couchpotato_dir}/data}
|
||||||
: ${couchpotato_pid:="${couchpotato_dir}/couchpotato.pid"}
|
: ${couchpotato_conf:=} #default is datadir/settings.conf
|
||||||
: ${couchpotato_conf:="${couchpotato_dir}/data/settings.conf"}
|
: ${couchpotato_pid:=} #default is datadir/couchpotato.pid
|
||||||
|
: ${couchpotato_flags:=}
|
||||||
|
|
||||||
WGET="/usr/local/bin/wget" # You need wget for this script to safely shutdown CouchPotato.
|
command="${couchpotato_dir}/CouchPotato.py"
|
||||||
|
command_interpreter="/usr/local/bin/python"
|
||||||
|
command_args="--daemon --data_dir ${couchpotato_datadir}"
|
||||||
|
|
||||||
status_cmd="${name}_status"
|
# append optional flags
|
||||||
stop_cmd="${name}_stop"
|
if [ -n "${couchpotato_pid}" ]; then
|
||||||
|
pidfile=${couchpotato_pid}
|
||||||
command="/usr/sbin/daemon"
|
couchpotato_flags="${couchpotato_flags} --pid_file ${couchpotato_pid}"
|
||||||
command_args="-f -p ${couchpotato_pid} /usr/local/bin/python ${couchpotato_dir}/CouchPotato.py --config_file ${couchpotato_conf} ${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
|
fi
|
||||||
|
if [ -n "${couchpotato_conf}" ]; then
|
||||||
# Ensure user is root when running this script.
|
couchpotato_flags="${couchpotato_flags} --config_file ${couchpotato_conf}"
|
||||||
if [ `id -u` != "0" ]; then
|
|
||||||
echo "Oops, you should be root before running this!"
|
|
||||||
exit 1
|
|
||||||
fi
|
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"
|
run_rc_command "$1"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user