From owner-svn-ports-head@FreeBSD.ORG Thu Dec 5 19:32:44 2013 Return-Path: Delivered-To: svn-ports-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 06C4FD9B; Thu, 5 Dec 2013 19:32:44 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E714715FE; Thu, 5 Dec 2013 19:32:43 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rB5JWhuA049117; Thu, 5 Dec 2013 19:32:43 GMT (envelope-from feld@svn.freebsd.org) Received: (from feld@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rB5JWhRs049103; Thu, 5 Dec 2013 19:32:43 GMT (envelope-from feld@svn.freebsd.org) Message-Id: <201312051932.rB5JWhRs049103@svn.freebsd.org> From: Mark Felder Date: Thu, 5 Dec 2013 19:32:43 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r335681 - in head/news/sabnzbdplus: . files X-SVN-Group: ports-head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the ports tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Dec 2013 19:32:44 -0000 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"