svn commit: r335681 - in head/news/sabnzbdplus: . files
Mark Felder
feld at FreeBSD.org
Thu Dec 5 19:32:44 UTC 2013
Author: feld
Date: Thu Dec 5 19:32:43 2013
New Revision: 335681
URL: http://svnweb.freebsd.org/changeset/ports/335681
Log:
Redesigned rc script to use a pidfile instead of attempting to use web API
which cannot stop the server in some configurations.
I've confirmed in the python codepath that both the web API shutdown and
the signal handling both call save_state() so it is safe to shutdown
this way.
PR: ports/177944
Approved by: crees (mentor)
Modified:
head/news/sabnzbdplus/Makefile
head/news/sabnzbdplus/files/sabnzbd.in
Modified: head/news/sabnzbdplus/Makefile
==============================================================================
--- head/news/sabnzbdplus/Makefile Thu Dec 5 19:13:14 2013 (r335680)
+++ head/news/sabnzbdplus/Makefile Thu Dec 5 19:32:43 2013 (r335681)
@@ -2,6 +2,7 @@
PORTNAME= sabnzbdplus
PORTVERSION= 0.7.16
+PORTREVISION= 1
CATEGORIES= news
MASTER_SITES= SF/${PORTNAME}/${PORTNAME}/${PORTVERSION}
DISTNAME= SABnzbd-${PORTVERSION}-src
@@ -70,10 +71,9 @@ USES= gettext
NO_BUILD= yes
WRKSRC= ${WRKDIR}/SABnzbd-${PORTVERSION}
PLIST_SUB= PORTNAME=${PORTNAME}
-SUB_LIST+= PORTNAME=${PORTNAME}
+SUB_LIST+= PORTNAME=${PORTNAME} PYTHON_CMD=${PYTHON_CMD}
SUB_FILES= pkg-message
USE_RC_SUBR= sabnzbd
-CONFLICTS_INSTALL= sabzndb-0.*
PORTDOCS= ABOUT.txt \
CHANGELOG.txt \
Modified: head/news/sabnzbdplus/files/sabnzbd.in
==============================================================================
--- head/news/sabnzbdplus/files/sabnzbd.in Thu Dec 5 19:13:14 2013 (r335680)
+++ head/news/sabnzbdplus/files/sabnzbd.in Thu Dec 5 19:32:43 2013 (r335681)
@@ -34,68 +34,22 @@ load_rc_config ${name}
: ${sabnzbd_group:=_sabnzbd}
: ${sabnzbd_conf_dir="%%PREFIX%%/sabnzbd"}
-required_dirs=${sabnzbd_conf_dir}
+pidfile=/var/run/sabnzbd/sabnzbd-$(grep -m1 ^port ${sabnzbd_conf_dir}/sabnzbd.ini | tr -dc '[0-9]').pid
-start_cmd="${name}_start"
-status_cmd="${name}_status"
-stop_cmd="${name}_stop"
start_precmd="${name}_prestart"
+extra_commands="status"
+command_interpreter="%%PYTHON_CMD%%"
+command="%%PREFIX%%/bin/SABnzbd.py"
+command_args="--daemon -f ${sabnzbd_conf_dir}/sabnzbd.ini --pid ${pidfile%/*}"
sabnzbd_prestart()
{
- PATH=${PATH}:%%PREFIX%%/bin:%%PREFIX%%/sbin
- if [ ! -f "${required_dirs}" -a ! -d "${required_dirs}" -a ! -L "${required_dirs}" ]; then
- install -d -o ${sabnzbd_user} -g ${sabnzbd_group} ${required_dirs}
- fi
-}
-
-sabnzbd_start()
-{
- if [ ! -f "${sabnzbd_pid}" ]; then
- su -m ${sabnzbd_user} -c "%%PREFIX%%/bin/SABnzbd.py --daemon -f ${sabnzbd_conf_dir}/sabnzbd.ini"
- echo "Starting ${name}."
- else
- GETPROCESSPID=`/bin/ps -auxw | /usr/bin/awk '/SABnzbd.py/ && !/awk/ && !/sh/ {print $2}'`
- PIDFROMFILE=`cat ${sabnzbd_pid}`
- if [ "$GETPROCESSPID" = "$PIDFROMFILE" ]; then
- echo "${name} already running with PID: ${PIDFROMFILE} ?"
- echo "Remove ${sabnzbd_pid} manually if needed."
- else
- rm -f ${sabnzbd_pid}
- su -m ${sabnzbd_user} -c "%%PREFIX%%/bin/SABnzbd.py --daemon -f ${sabnzbd_conf_dir}/sabnzbd.ini"
- echo "Starting ${name}."
+ PATH=${PATH}:/usr/local/bin:/usr/local/sbin
+ for sabdir in ${sabnzbd_conf_dir} ${pidfile%/*}; do
+ if [ ! -d "${sabdir}" ]; then
+ install -d -o ${sabnzbd_user} -g ${sabnzbd_group} ${sabdir}
fi
- fi
-}
-
-# SABnzbd can only be cleanly stopped by calling the http api
-sabnzbd_stop()
-{
- echo "Stopping $name"
- if [ -f "${sabnzbd_conf_dir}/sabnzbd.ini" ]; then
- apikey=`grep ^api_key ${sabnzbd_conf_dir}/sabnzbd.ini | tr -d " _"`
- host=`grep -m1 -E '^host\ =\ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' ${sabnzbd_conf_dir}/sabnzbd.ini | tr -dc '[0-9].'`
- if [ ${host} = "0.0.0.0" ] ; then
- host="localhost" ;
- fi
- port=`grep -m1 ^port ${sabnzbd_conf_dir}/sabnzbd.ini | tr -dc '[0-9]'`
- fetch -o /dev/null "http://${host}:${port}/api?mode=shutdown&${apikey}" > /dev/null 2>&1
- else
- sabnzbd_pid=`ps -U ${sabnzbd_user} | grep "python.*SABnzbd.py.*--daemon" | grep -v 'grep' | awk '{print $1}'`
- if [ -n "${sabnzbd_pid}" ]; then
- kill ${sabnzbd_pid}
- fi
- fi
-}
-
-sabnzbd_status()
-{
- sabnzbd_pid=`ps -U ${sabnzbd_user} | grep "python.*SABnzbd.py.*--daemon" | grep -v 'grep' | awk '{print $1}'`
- if [ -n "${sabnzbd_pid}" ]; then
- echo "$name is running as ${sabnzbd_pid}"
- else
- echo "$name is not running"
- fi
+ done
}
run_rc_command "$1"
More information about the svn-ports-head
mailing list