Init script For Linux (Running NZBGet On Boot)

Share your scripts or request scripts with specific features.
Forum rules
Please keep the forum clean - one topic per script. Questions not related to a specific script should be posted in Support forum.
Post Reply
war59312
Posts: 45
Joined: 12 Feb 2013, 04:52
Location: U.S.A
Contact:

Init script For Linux (Running NZBGet On Boot)

Post by war59312 » 28 Nov 2014, 02:05

Hi,

Thought I'd share my init Script that I use on Ubuntu Server.

Code: Select all

### 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
Little out dated already since nice and ionice has been added to scripts, but I want to be sure it takes place still. ;)

Don't forget to change "sudo - u rob" to your own account. And of course the paths that follow.

Enjoy,

Will
Last edited by war59312 on 12 Mar 2016, 02:13, edited 1 time in total.

svenglar
Posts: 4
Joined: 03 Aug 2015, 20:43

Re: Upstart Script For Ubuntu (Running NZBGet On Boot)

Post by svenglar » 03 Aug 2015, 21:00

Good stuff, but I just wanted to point out that this is not an Upstart script. What you have here is an init.d/sysvinit/init script.
Ubuntu, depending on the version, can handle both Upstart and sysvinit scripts. Upstart scripts go in

Code: Select all

/etc/init/
and sysvinit scripts go in

Code: Select all

/etc/init.d/
For anyone reading this that wants an Upstart script to handle NZBGet, you can start with the one I have below.
This is running on my Ubuntu 14.04 server.

Code: Select all

# FILE: /etc/init/nzbget

description "NZBGet upstart script"

setuid <replace_with_the_user_you_want>
setgid <replace_with_the_group_you_want>

start on runlevel [2345]
stop on runlevel [016]

respawn

expect fork

exec  <replace_with_the_path_to_nzbget> -D
pre-stop exec <replace_with_the_path_to_nzbget> -Q

Draky
Posts: 3
Joined: 18 Aug 2015, 08:38

Re: Upstart Script For Ubuntu (Running NZBGet On Boot)

Post by Draky » 18 Aug 2015, 11:24

Tried the upstart script but it does not work on my Ubuntu 15.04 :/

Here it is :

Code: Select all

# FILE: /etc/init/nzbget

description "NZBGet upstart script"

setuid gilles
setgid gilles

start on runlevel [2345]
stop on runlevel [016]

respawn

expect fork

exec /home/gilles/nzbget/nzbget -D -c /home/gilles/nzbget/nzbget.conf
pre-stop exec /home/gilles/nzbget/nzbget -Q
Have changer uid/gid to "root" but still not working.
Any idea on how to start NZBGet on startup ?

Of course, the command after exec works perfectly when launching from shell after Ubuntu starts and I get logged on...

dnvn
Posts: 1
Joined: 15 Oct 2015, 17:43

Re: Upstart Script For Ubuntu (Running NZBGet On Boot)

Post by dnvn » 15 Oct 2015, 17:47

In case you didn't find your answer, or for those searching, starting with 15.04 Ubuntu doesn't use Upstart by default. Here is a link on using Systemd or switching back to upstart: https://wiki.ubuntu.com/SystemdForUpstartUsers
Draky wrote:Tried the upstart script but it does not work on my Ubuntu 15.04 :/

Here it is :

Code: Select all

# FILE: /etc/init/nzbget

description "NZBGet upstart script"

setuid gilles
setgid gilles

start on runlevel [2345]
stop on runlevel [016]

respawn

expect fork

exec /home/gilles/nzbget/nzbget -D -c /home/gilles/nzbget/nzbget.conf
pre-stop exec /home/gilles/nzbget/nzbget -Q
Have changer uid/gid to "root" but still not working.
Any idea on how to start NZBGet on startup ?

Of course, the command after exec works perfectly when launching from shell after Ubuntu starts and I get logged on...

gewurz
Posts: 10
Joined: 26 Feb 2016, 18:30

Re: Upstart Script For Ubuntu (Running NZBGet On Boot)

Post by gewurz » 29 Feb 2016, 10:00


Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests