Kodi Community Forum
[LIVE] nzbget at startup - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: Linux (https://forum.kodi.tv/forumdisplay.php?fid=52)
+---- Thread: [LIVE] nzbget at startup (/showthread.php?tid=79262)



[LIVE] nzbget at startup - rozner9124 - 2010-08-19

Hi,


I've just recently got XBMC live running and it's working great. With much difficulty I've managed to get nzbget working. My only problem is that I can't get it start automatically. I have to ssh into the xbmc pc and start it manually whenever I turn the system on.

After some googling I found a startup script...
Code:
#!/bin/sh
# Start/stop the NZBget daemon.
#
case "$1" in
start)   echo -n "Start services: NZBget"
   /usr/local/bin/nzbget -D
   ;;
stop)   echo -n "Stop services: NZBget"
   /usr/local/bin/nzbget -Q
   ;;
restart)
   $0 stop
   $0 start
        ;;
*)   echo "Usage: $0 start|stop|restart"
        exit 1
        ;;
esac
exit 0

Then some more googling led me to this...

sudo update-rc.d defaults

It still doesn't work. I'm not sure if the script is running and then failing. I can't see any log messages. When XBMC boots there are 3 or 4 lines that appear but I can't read them since it's always blocked by the OSD on my TV and it's there for about half a second. I tried find a log that would show these messages but have been unsuccessful with that.

I've also tried update-rc.d with various different start, stop numbers to see if it changes anything but no difference.

Also I should mention that I have tested the startup script manually and it works fine. Just not at startup.

It would be really nice to get this working as I've installed samba so I can access the nzb drop directly from any PC on the network without the need to ssh into it and run commands.

Thanks for any help with this


- Xenomes - 2010-08-19

Autostart NZBGet

Get the autostart script with these commands:
Code:
sudo nano /etc/init.d/nzbget
Put your script in.
Code:
#!/bin/sh
# Start/stop the NZBget daemon.
#
case "$1" in
start)   echo -n "Start services: NZBget"
   /usr/local/bin/nzbget -D
   ;;
stop)   echo -n "Stop services: NZBget"
   /usr/local/bin/nzbget -Q
   ;;
restart)
   $0 stop
   $0 start
        ;;
*)   echo "Usage: $0 start|stop|restart"
        exit 1
        ;;
esac
exit 0
exit with ctrl+x
Code:
sudo chmod 755 /etc/init.d/nzbget
add NZBGet to the autostart routine with the following command:
Code:
sudo update-rc.d nzbget defaults



- rozner9124 - 2010-08-19

Thanks, I'm at work now but I'll try that when I get home


- rozner9124 - 2010-08-19

Actually this looks a lot like what I tried already and it's the same problem. Any other ideas?

For info... I compiled nzbget from source. Not sure if this makes any difference.


- rozner9124 - 2010-08-19

Update. I have determined that the script is definitely running at startup but the process is not starting correctly. Unfortunately nzbget doesn't seem to generate any log explaining why it doesn't start...


- rozner9124 - 2010-08-19

OK I figured it out, so in case anyone else ever runs into this problem. The problem was that it was running as "root" and looking for the config file in /root instead of /home/xbmc.

I found this by putting "ps -ef|grep nzbget > /home/xbmc/nzblog" into the startup script right after the call and I noticed it was running under root and executing /etc/rc2.d/S20nzbget.

Then I entered into root mode to test this (sudo -i). Trying to run it as root showed the message that the config file was not found. So I've change my script to:

Code:
su xbmc -c "/usr/local/bin/nzbget -D"
#same for stopping

Now it works fine. This was really frustrating yet such a simple solution. Anyway I hope this helps someone down the road.


RE: [LIVE] nzbget at startup - war59312 - 2013-02-12

Thanks Xenomes!

Here is my startup script.

Running NZBGet 9.1 on Ubuntu Server 12.10

Code:
# NZBGet With Nice And IONice Applied

description "nzbget"

#start on runlevel 2

stop on runlevel [!2345]

respawn
respawn limit 10 5
umask 022

case "$1" in
start)   echo -n "Start services: NZBget"
   exec sudo -u rob nice -n 19 ionice -c3 /usr/local/bin/nzbget -D -c /home/rob/.nzbget/nzbget.conf
   ;;
stop)   echo -n "Stop services: NZBget"
   exec sudo -u rob /usr/local/bin/nzbget -Q -c /home/rob/.nzbget/nzbget.conf
   ;;
restart)
   $0 stop
   $0 start
        ;;
*)   echo "Usage: $0 start|stop|restart"
        exit 1
        ;;
esac
exit 0

Updated Version:

Code:
### BEGIN INIT INFO
# Provides:          nzbget
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog    
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: spawns the nzbget processes
# Description:       spawns nzbget using start-stop-daemon
# Author:            Will
# Version:           1.0
### END INIT INFO

# respawn

SCRIPTNAME=/etc/init.d/nzbget

RETVAL=0

set -e

. /lib/lsb/init-functions

nzbget_running=`ps ax | grep "nzbget" | awk '{ print $1 }' | wc -l`

case "$1" in
    start)
    if [ "$nzbget_running" -gt 4 ]; then
        echo "Start: NZBGet Is Already Running"
        exit 0
    fi
    # echo -n "Start: Starting NZBGet"
    log_daemon_msg "Starting NZBGet"
        exec sudo -u rob nice -n 19 ionice -c3 /usr/local/bin/nzbget -D -c /home/rob/.nzbget/nzbget.conf >/dev/null 2>&1
        RETVAL=$?
    ;;
    stop)
    if [ "$nzbget_running" -lt 5 ]; then
        echo "Stop: NZBGet Is NOT Running"
        exit 0
    fi
    # echo -n "Stop: Killing NZBGet"
    log_daemon_msg "Killing All NZBGet Processes"
        exec sudo -u rob /usr/local/bin/nzbget -Q -c /home/rob/.nzbget/nzbget.conf >/dev/null 2>&1
        RETVAL=$?
    ;;

    status)
        if [ "$nzbget_running" -gt 4 ]; then
                echo "Status: NZBGet Is Running."
    else
        echo "Status: NZBGet Is NOT Running"
        fi
    ;;
    *)
    # echo "Usage: $0 {start|stop|status}"
    echo "Usage: $SCRIPTNAME {start|stop|status}" >&2
    exit 1
    ;;
esac
exit $RETVAL