# local script not starting



## blimy (Dec 13, 2011)

Hello, decided to try freebsd FreeBSD for a media server and loving it but running into one little snag.

So I installed sabnzbd from the ports system with portsnap, and it saved the startup script in /usr/local/etc/rc.d/sabnzbd.

I then added 
	
	



```
sabnzbd_enable="YES"
```
 to /etc/rc.conf.

Then I rebooted and I didn't see anything in the boot saying starting sabnzbd (saw starting sshd etc).

Lastly losing hope I moved it to /etc/rc.d/sabnzbd and on next reboot it worked fine, did I miss something? On Ubuntu Server I used to have to do *rc-update* but that doesn't seem to be the case, just want to make sure I'm not missing anything silly like when I got confused about not being able to use nano after downloading it, turns out i had to use *rehash*.

Also is there any danger in the file being in /etc/rc.d/ instead of /usr/local/etc/rc.d/? 

Anyway would feel better if I could understand why it doesn't seem to detect anything in /usr/local/etc/rc.d/ but does in /etc/rc.d/.

Thank you very much, loving freebsd FreeBSD so far


----------



## wblock@ (Dec 13, 2011)

No, don't move ports scripts into the base system.

As to why it didn't work, don't know.  After moving it back, what happens when starting it manually?
`# service sabnzbd start`


----------



## SirDice (Dec 13, 2011)

Move the script back to where it belongs, in /usr/local/etc/rc.d/.

Look with rcorder(8) and try starting it by hand (no need to reboot).

`# service sabnzbd start`


----------



## blimy (Dec 13, 2011)

Odd, I reinstalled the system two times (due to other problems) and kept having that problem. Now moved the sab script back to the /usr/ one and it worked fine. Should I always *service xxxx start* after installing something like sabnzbd and webmin etc for it to work on next reboot?

Going to reinstall the system since just testing stuff for now until all my hardware parts arrive and see how it will go. Using 8.2 by the way.

Thank you very much for the quick response wblock@


----------



## SirDice (Dec 13, 2011)

blimy said:
			
		

> should i always service xxxx start after installing something like sabnzbd and webmin etc ? for it to work on next reboots or ?


The service(8) command is for starting/stopping services by hand.


----------



## blimy (Dec 13, 2011)

Thanks as well SirDice. Ok, so I reinstalled freebsd FreeBSD with a minimal install, fetched latest ports, then extracted and *portsnap*'d sabnzbd. When it was done I added 
	
	



```
sabnzbd_enable="YES"
```
 to rc.conf.

Then did *service sabnzbd start*, and it started and I set it up etc.

Problem is that when I reboot it doesn't appear on the loading list, says "loading sshd keymap" etc. but sabnzbd doesn't appear (appeared on the previous install when I moved the sabnzbd script to /etc/rc.d/, and then when I moved it back to /usr/, but now reinstalled and did those things and it's not working. Trying to see if I can understand how I can use the rcorder.

Thanks


----------



## blimy (Dec 13, 2011)

Well, it starts manually fine, can't figure how to use *rcorder* but it starts and stops fine with the [cmd=]service sabnzbd start[/cmd]

Problem is that upon reboot nothing happens, doesn't say sabnzbd starting, but as soon as I moved it to /etc/rc.d/ on the previous install it picked it up right away. Not going to place it there again since it's not good, but not understanding why it's not picking up sab in the bootup


----------



## blimy (Dec 13, 2011)

Ok, so I install webmin and add it to the startup and even without aceessing webmin I reboot and all of a sudden sab works fine. Does the webmin post install script do something such as *rc-update*? Has to be an explanation why this is happening.


----------



## blimy (Dec 13, 2011)

So the problem here is sabnzbd not starting on boot, but if I install another ports package such as webmin and add it to rc.conf it will start working out of nowhere.

So here are the steps I did in each fresh install of FreeBSD 8.2.


```
portsnap fetch
portsnap fetch
portsnap update
cd /usr/ports/news/sabnzbdplus && make install
```
Then edit /etc/rc.conf and add 
	
	



```
sabnzbd_enable="YES"
```
Then I reboot and sabnzbd won't start.

Here's the sabnzbd script (it works by starting it manually or after I add webmin to the rc.conf)


```
#!/bin/sh
#
# 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=${name}_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"
```

Thank you


----------



## blimy (Dec 14, 2011)

Hello, please add 'solved' to the title since I can't edit yet.

Was fiddling with it again today and noticed that it was starting sabnzbd too soon.

So added 
	
	



```
# REQUIRE: LOGIN cleanvar
```
 to the script and now it's working fine.

Thanks for your help.


----------



## SirDice (Dec 14, 2011)

If you use DHCP setting the interface to SYNCDHCP instead of just DHCP might help too.

It's possible sabnzb tried to start before the interface got a chance to get an IP address assigned.


----------



## blimy (Dec 14, 2011)

Just one more thing: how can I get the sabnzbd script I posted before to call python in /usr/local/bin instead of /usr/bin since after manually installing SABnzbd and try to start it it says 
	
	



```
SABnzbd.py : command not found.
```

I copied python to /usr/bin and it ran without any problems, since I want things as clean as possible without having to use *ln -s*, is there any way to tell the script that python is in /usr/local/bin?

If I install it from ports it works fine with that same script so I guess it has some post install routine to fix that.

Thanks in advance.


----------



## blimy (Dec 14, 2011)

Never mind the above post, this is now fixed as well.

Thanks for everything 



			
				blimy said:
			
		

> Just one more thing , how can i get the sabnzbd script i posted before to call python in /usr/local/bin instead of /usr/bin since after manually installing SABnzbd and try to start it it says SABnzbd.py : command not found.
> 
> I copied python to /usr/bin and it ran without any problems , since i want things as clean as possible without having to use ln -s , is there any way to tell the script that python is in /usr/local/bin ?
> 
> ...


----------

