diff --git a/.gitignore b/.gitignore index f903669..bd4bca0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/_source/ \ No newline at end of file +/_source/ +/data/ diff --git a/couchpotato/core/helpers/variable.py b/couchpotato/core/helpers/variable.py index 9a4bdc1..493ac79 100644 --- a/couchpotato/core/helpers/variable.py +++ b/couchpotato/core/helpers/variable.py @@ -5,6 +5,7 @@ import platform import random import re import string +import sys log = CPLog(__name__) @@ -22,6 +23,10 @@ def getDataDir(): if 'darwin' in platform.platform().lower(): return os.path.join(user_dir, 'Library', 'Application Support', 'CouchPotato') + # FreeBSD + if 'freebsd' in sys.platform: + return os.path.join('/usr/local/', 'couchpotato', 'data') + # Linux return os.path.join(user_dir, '.couchpotato') diff --git a/init/freebsd b/init/freebsd index e3cf408..eeba51d 100644 --- a/init/freebsd +++ b/init/freebsd @@ -31,14 +31,27 @@ load_rc_config ${name} : ${couchpotato_user:="_sabnzbd"} : ${couchpotato_dir:="/usr/local/couchpotato"} : ${couchpotato_chdir:="${couchpotato_dir}"} -: ${couchpotato_pid:="/var/run/couchpotato.pid"} +: ${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}"|egrep "^host"|perl -wple 's/^host = (.*)$/$1/'` + PORT=`grep -A14 "\[core\]" "${couchpotato_conf}"|egrep "^port"|perl -wple 's/^port = (.*)$/$1/'` + CPAPI=`grep -A14 "\[core\]" "${couchpotato_conf}"|egrep "^api_key"|perl -wple 's/^api_key = (.*)$/$1/'` +fi -pidfile="${couchpotato_pid}" 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} --pid_file=${couchpotato_pid}" +command_args="-f -p ${couchpotato_pid} python ${couchpotato_dir}/CouchPotato.py ${couchpotato_flags}" + +# 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 @@ -55,17 +68,17 @@ verify_couchpotato_pid() { # 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 echo "Stopping $name" verify_couchpotato_pid - + ${WGET} -O - -q "http://${HOST}:${PORT}/api/${CPAPI}/app.shutdown/" >/dev/null if [ -n "${pid}" ]; then - kill -SIGTERM ${pid} 2> /dev/null wait_for_pids ${pid} - kill -9 ${pid} 2> /dev/null echo "Stopped" fi - } couchpotato_status() {