[System Init Script] Start NZBGet on system 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
hugbug
Developer & Admin
Posts: 6589
Joined: 09 Sep 2008, 11:58
Location: Germany (NRW)

[System Init Script] Start NZBGet on system boot

Post by hugbug » 30 Oct 2016, 11:31

The solution to start on boot depends on the init system used.

There are three common init systems used on Linux: systemd, upstart, sysv-init.

Copied from page How to find out if a system uses SysV, Upstart or Systemd initsystem:
You can poke around the system to find indicators. One way is to check for the existence of three directories:
  • /usr/lib/systemd tells you you're on a systemd based system.
  • /usr/share/upstart is a pretty good indicator that you're on an Upstart-based system.
  • /etc/init.d tells you the box has SysV init in its history
The thing is, these are heuristics that must be considered together, possibly with other data, not certain indicators by themselves. The Ubuntu 14.10 box I'm looking at right now has all three directories. Why? Because Ubuntu just switched to systemd from Upstart in that version, but keeps Upstart and SysV init for backwards compatibility.

In the end, I think the best answer is "experience." You will see that you have logged into a CentOS 7 box and know that it's systemd. How do you learn this? Playing around, RTFMing, etc. The same way you gain all experience.

I realize this is not a very satisfactory answer, but that's what happens when there is fragmentation in the market, creating nonstandard designs.
I've collected the following solutions from various sources, mainly from topic Init script For Linux (Running NZBGet On Boot), which has become hard to follow.

I didn't have a chance to test these scripts myself. If you find errors please report here in this topic and I'll update the first post. The goal is to keep the first post up-to-date.


Systemd

Create file /usr/lib/systemd/system/nzbget.service with the following content:

Code: Select all

[Unit]
Description=NZBGet Daemon
Documentation=http://nzbget.net/Documentation
After=network.target

[Service]
User=<replace_with_the_user_you_want>
Group=<replace_with_the_group_you_want>
Type=forking
ExecStart=</path/to/nzbget/nzbget> -D
ExecStop=</path/to/nzbget/nzbget> -Q
ExecReload=</path/to/nzbget/nzbget> -O
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target
Adjust <replace_with_the_user_you_want>, <replace_with_the_group_you_want> and </path/to/nzbget/nzbget>.


Upstart

Create file /etc/init/nzbget:

Code: Select all

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  </path/to/nzbget/nzbget> -D
pre-stop exec </path/to/nzbget/nzbget> -Q
Adjust <replace_with_the_user_you_want>, <replace_with_the_group_you_want> and </path/to/nzbget/nzbget>.


SysV Init

Create file /etc/init.d/nzbget:

Code: Select all

#!/bin/sh
# Start/stop the NZBget daemon.
#
case "$1" in
start)   echo -n "Start services: NZBget"
</path/to/nzbget/nzbget> -D
;;
stop)   echo -n "Stop services: NZBget"
</path/to/nzbget/nzbget> -Q
;;
*)   echo "Usage: $0 start|stop"
exit 1
;;
esac
exit 0
Adjust </path/to/nzbget/nzbget>. Then make the file executable and update the init.d to be used at boot with command:

Code: Select all

chmod +x /etc/init.d/nzbget && update-rc.d nzbget defaults

voona
Posts: 4
Joined: 10 Jan 2017, 14:45

Re: [System Init Script] Start NZBGet on system boot

Post by voona » 11 Jan 2017, 11:30

Tested on Linux Mint 18.1
To autostart nzbget on boot I used the nzbget.service from above (reposted the code below) and put it in:
/lib/systemd/system (instead of /usr/lib/systemd/system/)

then enable it via: sudo systemctl enable nzbget.service
reboot or start service manually: sudo systemctl start nzbget.service
to check status: sudo systemctl status nzbget.service

Code: Select all

[Unit]
Description=NZBGet Daemon
Documentation=http://nzbget.net/Documentation
After=network.target

[Service]
User=<replace_with_the_user_you_want>
Group=<replace_with_the_group_you_want>
Type=forking
ExecStart=</path/to/nzbget/nzbget> -D
ExecStop=</path/to/nzbget/nzbget> -Q
ExecReload=</path/to/nzbget/nzbget> -O
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target
Adjust <replace_with_the_user_you_want>, <replace_with_the_group_you_want> and </path/to/nzbget/nzbget>.

hieroglyph
Posts: 1
Joined: 20 Apr 2017, 23:47

Re: [System Init Script] Start NZBGet on system boot

Post by hieroglyph » 21 Apr 2017, 00:00

This took me a minute to figure out. Using the Upstart option on Linux Mint 17.3 (aka Ubuntu 14.04) I was not able to get it to work until I added the .conf extension to the file name.

Upstart

Create file /etc/init/nzbget.conf:

:o

zmanfarlee
Posts: 5
Joined: 10 Mar 2015, 14:30

Re: [System Init Script] Start NZBGet on system boot

Post by zmanfarlee » 22 Jul 2017, 22:08

THANK YOU SO MUCH!!

This worked for raspberry pi running Jesse
voona wrote:
11 Jan 2017, 11:30
Tested on Linux Mint 18.1
To autostart nzbget on boot I used the nzbget.service from above (reposted the code below) and put it in:
/lib/systemd/system (instead of /usr/lib/systemd/system/)

then enable it via: sudo systemctl enable nzbget.service
reboot or start service manually: sudo systemctl start nzbget.service
to check status: sudo systemctl status nzbget.service

Code: Select all

[Unit]
Description=NZBGet Daemon
Documentation=http://nzbget.net/Documentation
After=network.target

[Service]
User=<replace_with_the_user_you_want>
Group=<replace_with_the_group_you_want>
Type=forking
ExecStart=</path/to/nzbget/nzbget> -D
ExecStop=</path/to/nzbget/nzbget> -Q
ExecReload=</path/to/nzbget/nzbget> -O
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target
Adjust <replace_with_the_user_you_want>, <replace_with_the_group_you_want> and </path/to/nzbget/nzbget>.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest