From nobody@FreeBSD.org  Thu Jan 26 03:15:51 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id B56501065676
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Jan 2012 03:15:51 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id A4C708FC17
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Jan 2012 03:15:51 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q0Q3FpSG092424
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Jan 2012 03:15:51 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q0Q3FpLS092423;
	Thu, 26 Jan 2012 03:15:51 GMT
	(envelope-from nobody)
Message-Id: <201201260315.q0Q3FpLS092423@red.freebsd.org>
Date: Thu, 26 Jan 2012 03:15:51 GMT
From: Tom <tgord@mm.st>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] sabnzbd not starting on boot
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         164502
>Category:       ports
>Synopsis:       [patch] news/sabnzbdplus not starting on boot
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    scheidell
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 26 03:20:01 UTC 2012
>Closed-Date:    Mon Apr 30 07:13:20 UTC 2012
>Last-Modified:  Mon Apr 30 07:13:20 UTC 2012
>Originator:     Tom
>Release:        9.0-RELEASE
>Organization:
>Environment:
FreeBSD sivert 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:30 UTC 2012     root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
sabnzbd was not starting on boot despite rc.conf containing the required 'sabnzbd_enable="YES"' and the manual execution of 'service sabnzbd start' working just fine. Service logs did not contain any abnormal (and therefore useful) information
>How-To-Repeat:
Install sabnzbdplus from ports, set it up to start on boot and observe when it (presumably) doesn't. There might be some variability here as I've seen reports on the forum of it 'suddenly working' when other ports are installed with services enabled at boot time.
>Fix:
Per http://forums.freebsd.org/showthread.php?t=28310, adding 'REQUIRE: LOGIN cleanvar' seems to do the trick, though I don't grasp what this is *actually* requiring and can't seem to find the provider myself (this is probably mostly due to my current ineptitude). I've attached my modified startup script for consideration.

Patch attached with submission follows:

#!/bin/sh
#
# REQUIRE: LOGIN cleanvar
# PROVIDE: sabnzbd
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# sabnzbd_enable (bool):        Set to NO by default.
#                       Set it to YES to enable it.
# sabnzbd_conf_dir:     Directory where sabnzbd configuration
#                       data is stored.
#                       Default: /usr/local/sabnzbd
# sabnzbd_user:         The user account sabnzbd 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.
# sabnzbd_group:        The group account sabnzbd daemon runs as what
#                       you want it to be. It uses '_sabnzbd' group by
#                       default. Do not sets it as empty or it will run
#                       as wheel.

. /etc/rc.subr

name="sabnzbd"
rcvar=sabnzbd_enable

load_rc_config ${name}

: ${sabnzbd_enable:="NO"}
: ${sabnzbd_user:="_sabnzbd"}
: ${sabnzbd_group:="_sabnzbd"}
: ${sabnzbd_conf_dir:="/usr/local/sabnzbd"}

required_dirs=${sabnzbd_conf_dir}

start_cmd="${name}_start"
#start_postcmd="${name}_poststart"
status_cmd="${name}_status"
stop_cmd="${name}_stop"
start_precmd=sabnzbd_check_dir



sabnzbd_start()
{
if [ ! -f "${sabnzbd_pid}" ]; then
    su -m ${sabnzbd_user} -c "/usr/local/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 "/usr/local/bin/SABnzbd.py --daemon -f ${sabnzbd_conf_dir}/sabnzbd.ini"
        echo "Starting ${name}."
    fi
fi
}

#sabnzbd_poststart() {
#  echo `/bin/ps -auxw | /usr/bin/awk '/SABnzbd.py/ && !/awk/ {print $2}'` > $sabnzbd_pid
#}

# 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
}

sabnzbd_check_dir() {
    if [ ! -f "${required_dirs}" -a ! -d "${required_dirs}" -a ! -L "${required_dirs}" ]; then
        mkdir -p ${required_dirs}
        chown ${sabnzbd_user}:${sabnzbd_group} ${required_dirs}
    fi
}

run_rc_command "$1"


>Release-Note:
>Audit-Trail:

From: David Brooks <dab@rj45.org>
To: bug-followup@FreeBSD.org, tgord@mm.st
Cc:  
Subject: Re: ports/164502: [patch] news/sabnzbdplus not starting on boot
Date: Thu, 8 Mar 2012 13:56:12 -0500

 --f46d044287a66c8a2704babfd488
 Content-Type: text/plain; charset=UTF-8
 
 I just noticed this PR -- I'll be looking into it shortly.
 
 -- 
 "With sufficient thrust, pigs fly just fine." -- RFC1925
 
 --f46d044287a66c8a2704babfd488
 Content-Type: text/html; charset=UTF-8
 
 I just noticed this PR -- I&#39;ll be looking into it shortly.<br clear="all"><div><br></div>-- <br>&quot;With sufficient thrust, pigs fly just fine.&quot; -- RFC1925<br><br>
 
 --f46d044287a66c8a2704babfd488--
Responsible-Changed-From-To: freebsd-ports-bugs->scheidell 
Responsible-Changed-By: scheidell 
Responsible-Changed-When: Fri Apr 20 09:17:40 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=164502 
State-Changed-From-To: open->feedback 
State-Changed-By: scheidell 
State-Changed-When: Fri Apr 20 09:23:34 UTC 2012 
State-Changed-Why:  
Submitter: Thank you for your pr submission.  it did not actually contain a patch, which might have been applied earlier. 
Could you check to see if this patch is what you are looking for? 
(and, please update your ports tree first.  A couple of updates have happened since, make sure this is still needed) 
diff -u -r1.4 sabnzbd.in 
--- files/sabnzbd.in	14 Jan 2012 08:56:44 -0000	1.4 
+++ files/sabnzbd.in	20 Apr 2012 09:22:07 -0000 
@@ -1,5 +1,6 @@ 
#!/bin/sh 
# 
+# REQUIRE: LOGIN cleanvar 
# PROVIDE: sabnzbd 
# KEYWORD: shutdown 
# 


http://www.freebsd.org/cgi/query-pr.cgi?pr=164502 
State-Changed-From-To: feedback->closed 
State-Changed-By: scheidell 
State-Changed-When: Mon Apr 30 07:13:19 UTC 2012 
State-Changed-Why:  
Submitted did not submit a patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=164502 
>Unformatted:
