Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # PROVIDE: HTPC manager
- #
- # Add the following lines to /etc/rc.conf.local or /etc/rc.conf or make a seperate script
- # to enable this service:
- #
- # HTPC_manager_enable (bool): Set to NO by default.
- # Set it to YES to enable it.
- # HTPC_manager_user: The user account HTPC manager 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.
- # HTPC_manager_dir: Directory where HTPC manager lives.
- # Default: /usr/local/HTPC_manager
- # HTPC_manager_chdir: Change to this directory before running HTPC manager.
- # Default is same as HTPC_manager_dir.
- # HTPC_manager_pid: The name of the pidfile to create.
- # Default is htpc.pid in HTPC_manager_dir.
- . /etc/rc.subr
- name="HTPC_manager"
- rcvar=${name}_enable
- load_rc_config ${name}
- : ${HTPC_manager_enable:="YES"}
- : ${HTPC_manager_user:=""}
- : ${HTPC_manager_dir:="/mnt/data/programs/manager"}
- : ${HTPC_manager_chdir:="${HTPC_manager_dir}"}
- : ${HTPC_manager_pid:="${HTPC_manager_dir}/htpc.pid"}
- : ${HTPC_manager_conf:="${HTPC_manager_dir}/userdata/settings.conf"}
- WGET="/usr/local/bin/wget" # You need wget for this script to safely shutdown CouchPotato.
- if [ -e "${HTPC_manager_conf}" ]; then
- HOST=`grep -A14 "\[core\]" "${HTPC_manager_conf}"|egrep "^host"|perl -wple 's/^host = (.*)$/$1/'`
- PORT=`grep -A14 "\[core\]" "${HTPC_manager_conf}"|egrep "^port"|perl -wple 's/^port = (.*)$/$1/'`
- CPAPI=`grep -A14 "\[core\]" "${HTPC_manager_conf}"|egrep "^api_key"|perl -wple 's/^api_key = (.*)$/$1/'`
- fi
- status_cmd="${name}_status"
- stop_cmd="${name}_stop"
- command="/usr/sbin/daemon"
- command_args="-f -p ${HTPC_manager_pid} python ${HTPC_manager_dir}/htpc.py ${HTPC_manager_flags}"
- # Check for wget and refuse to start without it.
- if [ ! -x "${WGET}" ]; then
- warn "HTPC manager not started: You need wget to safely shut down HTPC manager."
- 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_HTPC_manager_pid() {
- # Make sure the pid corresponds to the CouchPotato process.
- pid=`cat ${HTPC_manager_pid} 2>/dev/null`
- ps -p ${pid} | grep -q "python ${HTPC_manager_dir}/htpc.py"
- return $?
- }
- # Try to stop HTPC manager cleanly by calling shutdown over http.
- couchpotato_stop() {
- if [ ! -e "${HTPC_manager_conf}" ]; then
- echo "HTPC manager settings file does not exist. Try starting HTPC manager, as this should create the file."
- exit 1
- fi
- echo "Stopping $name"
- verify_HTPC_manager_pid
- ${WGET} -O - -q "http://${HOST}:${PORT}/api/${CPAPI}/app.shutdown/" >/dev/null
- if [ -n "${pid}" ]; then
- wait_for_pids ${pid}
- echo "Stopped"
- fi
- }
- HTPC_manager_status() {
- verify_HTPC_manager_pid && echo "$name is running as ${pid}" || echo "$name is not running"
- }
- run_rc_command "$1"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement