[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.
hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

[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>.

Commander
Posts: 4
Joined: 27 Dec 2017, 14:59

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

Post by Commander » 28 Dec 2017, 15:26

Ok I start NZBget with systemd. All work fine but the Extension Script Notify - notifications (All In One) crash on test. I think the problem is that OpenSSL isn`t start if NZBget strated. If there a change for waiting before nzbget.service started?

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

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

Post by hugbug » 28 Dec 2017, 21:34

Openssl isn't a service and therefore doesn't start on system boot. If you start nzbget not from boot script does the script work?

buggy13
Posts: 34
Joined: 07 Sep 2014, 12:20

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

Post by buggy13 » 18 Oct 2018, 17:29

i'm running nzbget on a raspberry pi with raspbian stretch. sometimes autostart with systemd works and sometimes not. at the moments its running but there is an error if i run systemd status nzbget

Code: Select all

nzbget.service - NZBGet Daemon
   Loaded: loaded (/usr/lib/systemd/system/nzbget.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-10-18 16:25:13 CEST; 2h 55min ago
     Docs: http://nzbget.net/Documentation
  Process: 625 ExecStop=/home/pi/.nzbget/nzbget -Q (code=exited, status=1/FAILURE)
  Process: 649 ExecStart=/home/pi/.nzbget/nzbget -D (code=exited, status=0/SUCCESS)
 Main PID: 660 (nzbget)
   CGroup: /system.slice/nzbget.service
           └─660 /home/pi/.nzbget/nzbget -D

Okt 18 16:25:13 raspberrypi systemd[1]: Starting NZBGet Daemon...
Okt 18 16:25:13 raspberrypi systemd[1]: Started NZBGet Daemon.
this is the status when auto start doesn't work:

Code: Select all

● nzbget.service - NZBGet Daemon
   Loaded: loaded (/usr/lib/systemd/system/nzbget.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2018-10-12 15:17:15 CEST; 5 days ago
     Docs: http://nzbget.net/Documentation
  Process: 669 ExecStop=/home/pi/.nzbget/nzbget -Q (code=exited, status=1/FAILURE)
  Process: 666 ExecStart=/home/pi/.nzbget/nzbget -D (code=exited, status=0/SUCCESS)
 Main PID: 600 (code=exited, status=1/FAILURE)

Okt 12 15:17:15 raspberrypi systemd[1]: nzbget.service: Control process exited, code=exited status=1
Okt 12 15:17:15 raspberrypi systemd[1]: Failed to start NZBGet Daemon.
Okt 12 15:17:15 raspberrypi systemd[1]: nzbget.service: Unit entered failed state.
Okt 12 15:17:15 raspberrypi systemd[1]: nzbget.service: Failed with result 'exit-code'.
Okt 12 15:17:15 raspberrypi systemd[1]: nzbget.service: Service hold-off time over, scheduling restart.
Okt 12 15:17:15 raspberrypi systemd[1]: Stopped NZBGet Daemon.
Okt 12 15:17:15 raspberrypi systemd[1]: nzbget.service: Start request repeated too quickly.
Okt 12 15:17:15 raspberrypi systemd[1]: Failed to start NZBGet Daemon.
Okt 12 15:17:15 raspberrypi systemd[1]: nzbget.service: Unit entered failed state.
Okt 12 15:17:15 raspberrypi systemd[1]: nzbget.service: Failed with result 'exit-code'.

buggy13
Posts: 34
Joined: 07 Sep 2014, 12:20

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

Post by buggy13 » 21 Nov 2018, 10:34

no ideas?

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

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

Post by hugbug » 21 Nov 2018, 11:33

Maybe try logging the output of nzbget command into a file? Something like:

Code: Select all

ExecStart=/home/pi/.nzbget/nzbget -D >> /home/pi/.nzbget/startlog.txt
ExecStop=/home/pi/.nzbget/nzbget -Q >> /home/pi/.nzbget/stoplog.txt

buggy13
Posts: 34
Joined: 07 Sep 2014, 12:20

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

Post by buggy13 » 22 Nov 2018, 12:46

The files are not created after reboot. Is there a different between /usr/lib/systemd/system and /etc/systemd/system on raspberry pi? normally i created all the service files in /etc/systemd/system instead of /usr/lib/...

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests