Systemd startup scripts for Sonarr and Nzbget

osmc@osmc:~$ ls -la /mnt/INTENSO
total 32
drwxrwxrwx 1 osmc osmc 0 Jul 27 11:26 $RECYCLE.BIN
drwxrwxrwx 1 osmc osmc 20480 Jul 27 11:26 .
drwxr-xr-x 3 root root 4096 Jul 27 16:11 …
drwxrwxrwx 1 osmc osmc 4096 Jul 24 09:52 Movies
drwxrwxrwx 1 osmc osmc 0 Jul 26 16:33 Series
drwxrwxrwx 1 osmc osmc 0 Jul 24 09:51 System Volume Information
drwxrwxrwx 1 osmc osmc 4096 Jul 18 07:16 nzbget

no permission issue…
just reinstalled and made /mnt/INTENSO my mount point.
now I’ll install nzbget using your tutorial and follow it to the letter…:slight_smile:
(by the way, the link to nzbget in your tutorial is dead, I have to get nzbget 16.4 from nzbget.net)
will report back…fingers crossed

Thanks, I have fixed the link. Please get back to me, I’ve only used the tutorial for myself, so to have someone else use it is really useful feedback.

It worked!!!

after I mounted my external drive I was able to install nzbget, sonarr AND couchpotatoe and they are still running after a reboot!

what caused the previous issues, I don’t know…my guess is that I forgot to upgrade the packages before installing nzbget.

your guide is great! Thank you so much for your help!

1 Like

Happy to help :grinning:

Didn’t know about OnBootSec, and have been putting /bin/sleep in our ExecStartPre= for some scripts.

Nice one!

1 Like

Thank you for all your hard work Sam. :slight_smile:

Hello @eekfonky,

Do you still have your guide posted anywhere else? The link you provided earlier appears to be expired.

I’m trying to get Nzbget on rPi3 starting on boot with all paths pointing to an external USB drive. Of course, currently OSMC mounts the drive long after systemd tries to start Nzbget so it never properly starts. Once the rPi3 is up though and OSMC mounts the drive, issuing systemctl manually starts it up no problem.

If I understand correctly it appears you use fstab to mount the USB drive first and use “RequiresMountFor” to ensure the drive is up before Nzbget is started.

Does mounting the USB drive using FSTAB affect OSMC’s visibility of the drive at all other than having to change all paths from “/media/My Passport” to “/mnt/USBdrive” for example?

I’m no Linux guru by any means so it seems your guide would probably answer my questions.

Thanks for looking into this and sharing the information!
-stevewk

Edit: Just for the sake of completeness this is the systemd status after a reboot:

osmc@osmc:~$ sudo systemctl status nzbget

  • nzbget.service - NZBGet
    Loaded: loaded (/etc/systemd/system/nzbget.service; enabled)
    Active: inactive (dead) since Tue 2016-11-08 11:50:22 EST; 1min 40s ago
    Process: 389 ExecStop=/opt/nzbget/nzbget -Q (code=exited, status=0/SUCCESS)
    Process: 285 ExecStart=/opt/nzbget/nzbget -D (code=exited, status=0/SUCCESS)

Nov 08 11:50:22 osmc nzbget[285]: nzbget.conf(52): Invalid value for option…ed
Nov 08 11:50:22 osmc nzbget[285]: nzbget.conf(46): Invalid value for option…ed
Nov 08 11:50:22 osmc nzbget[389]: /media/My Passport/downloads/nzbget.log: …ry
Nov 08 11:50:22 osmc nzbget[389]: /media/My Passport/downloads/nzbget.log: …ry
Nov 08 11:50:22 osmc nzbget[389]: /media/My Passport/downloads/nzbget.log: …ry
Nov 08 11:50:22 osmc nzbget[389]: nzbget.conf(55): Invalid value for option…ed
Nov 08 11:50:22 osmc nzbget[389]: nzbget.conf(52): Invalid value for option…ed
Nov 08 11:50:22 osmc nzbget[389]: nzbget.conf(46): Invalid value for option…ed
Nov 08 11:50:22 osmc nzbget[389]: Unable to send request to nzbget-server a…9)
Nov 08 11:50:22 osmc systemd[1]: Started NZBGet.
Hint: Some lines were ellipsized, use -l to show in full.

trying to migrate the stuff here;
https://lexiconitltd.com/media-centre/nzbget/

Might not have everything yet until the weekend though.

Also what does your fstab look like and can you use the -l on sudo systemctl -l status nzbget

Plus the systemd file and where you saved the nzbget files? e.g. are they ctually in /opt

Thanks for the quick response and link update! As I said, I’m not an experienced Linux user so I’m just figuring out the mounting part before I move to adding the “RequiresForMount” part to the systemd file. Will start trying that out tonight now that I’ve gotten an idea of what needs to be done from all your previous posts.

Here is the -l of the systemctl status…as you can see all due to the external USB drive not being mounted first:

osmc@osmc:~$ sudo systemctl -l status nzbget

  • nzbget.service - NZBGet
    Loaded: loaded (/etc/systemd/system/nzbget.service; enabled)
    Active: inactive (dead) since Tue 2016-11-08 15:23:38 EST; 1min 25s ago
    Process: 373 ExecStop=/opt/nzbget/nzbget -Q (code=exited, status=0/SUCCESS)
    Process: 287 ExecStart=/opt/nzbget/nzbget -D (code=exited, status=0/SUCCESS)

Nov 08 15:23:37 osmc nzbget[287]: nzbget.conf(52): Invalid value for option “QueueDir” (/ media/My Passport/downloads/queue): could not create directory /media/My Passport: Permis sion denied
Nov 08 15:23:37 osmc nzbget[287]: nzbget.conf(46): Invalid value for option “NzbDir” (/me dia/My Passport/downloads/nzb): could not create directory /media/My Passport: Permission denied
Nov 08 15:23:38 osmc nzbget[373]: /media/My Passport/downloads/nzbget.log: No such file o r directory
Nov 08 15:23:38 osmc nzbget[373]: /media/My Passport/downloads/nzbget.log: No such file o r directory
Nov 08 15:23:38 osmc nzbget[373]: /media/My Passport/downloads/nzbget.log: No such file o r directory
Nov 08 15:23:38 osmc nzbget[373]: nzbget.conf(55): Invalid value for option “TempDir” (/m edia/My Passport/downloads/tmp): could not create directory /media/My Passport: Permissio n denied
Nov 08 15:23:38 osmc nzbget[373]: nzbget.conf(52): Invalid value for option “QueueDir” (/ media/My Passport/downloads/queue): could not create directory /media/My Passport: Permis sion denied
Nov 08 15:23:38 osmc nzbget[373]: nzbget.conf(46): Invalid value for option “NzbDir” (/me dia/My Passport/downloads/nzb): could not create directory /media/My Passport: Permission denied
Nov 08 15:23:38 osmc nzbget[373]: Unable to send request to nzbget-server at 127.0.0.1 (p ort 6789)
Nov 08 15:23:38 osmc systemd[1]: Started NZBGet.

This my current fstab…I haven’t yet tried mounting the USB drive there as I’m not 100% clear on the syntax and path just yet. Appears to only be the boot and main partitions on the microSD currently:

osmc@osmc:~$ cat /etc/fstab
/dev/mmcblk0p1 /boot vfat defaults,noatime 0 0
/dev/mmcblk0p2 / ext4 defaults,noatime 0 0

This is the USB drive that I assume I will have to mount in “fstab” so just trying to sort what the fstab syntax will be for this drive?:

sudo fdisk -l

Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 975400959 975398912 465.1G 7 HPFS/NTFS/exFAT

This is the systemd file, and yes “nzbget” exists under the “/opt/nzbget” path…I haven’t added the “RequiresMountFor=” line yet as I wanted to work on getting the USB drive mounted first:

Edit: Sorry looks like the # is formatting the commented out parts of the file so I’ve added some “” around those lines for this webpage only (they don’t exist on my rPi)

osmc@osmc:~$ cat /etc/systemd/system/nzbget.service
[Unit]
Description=NZBGet
After=network.target
“#RequiresMountsFor=”

[Service]
User=osmc
Group=osmc
ExecStart=/opt/nzbget/nzbget -D
ExecStop=/opt/nzbget/nzbget -Q
“# process will demonize and parent return ok”
Type=forking
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process

[Install]
“# Needed to run nzbget at boot”
WantedBy=multi-user.target

I’ll check out the Wiki for fstab you have in your guide and see if I can get the syntax right. If you know off hand of course I’d appreciate any tips you might have.

Thanks again!

OK looks like it’s not working as it requires the USB drive to be mounted.
Make sure it’s plugged in (obviously), then do the following;
cd /dev/disk/by-uuid
ls -la

It’ll probably be the sda one and NOT the mmcblk0p1
mine looks like this;

pi@pi3-server:/dev/disk/by-uuid $ ls -la
total 0
drwxr-xr-x 2 root root 100 Oct 30 19:40 .
drwxr-xr-x 6 root root 120 Oct 30 19:40 ..
lrwxrwxrwx 1 root root  10 Oct 30 19:40 15c34a6b-f0af-4d24-b546-0eaeaec9ee33 -> ../../sda1
lrwxrwxrwx 1 root root  15 Oct 30 19:40 3598ef8e-09be-47ef-9d01-f24cf61dff1d -> ../../mmcblk0p2
lrwxrwxrwx 1 root root  15 Oct 30 19:40 70F7-FA1D -> ../../mmcblk0p1

The one with sda1 is the UUID for the external USB. So I mounted it in the fstab like this;

pi@pi3-server:~ $ sudo nano /etc/fstab 
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
UUID=15c34a6b-f0af-4d24-b546-0eaeaec9ee33 /mnt/extHD    ext4      nofail,defaults    0  0

/mnt/extHD is where I have mounted the drive in the OSMC file system. (You may need to create the directory first with sudo mkdir /mnt/YOUR_DIRECTORY_NAME)

The ext4 is the filesystem I have, yours may be fat32 or NTFS (whatever it’s formatted as)

The nofail,defaults 0 0 are just the default option here, it’ll do the trick.

Save & exit
Mount it sudo mount -a

Check it with df.

Now you need to make sure the systemd file for NZBget is working. Try the above first and let me know if you get stuck?

Here’s mine;

[Unit]
Description=NZBGet Daemon
After=network.target
RequiresMountsFor=/mnt/extHD
 
[Service]
User=osmc
Group=osmc
Type=forking
ExecStart=/opt/nzbget/nzbget -c /opt/nzbget/nzbget.conf -D
ExecStop=/opt/nzbget/nzbget -Q
ExecReload=/opt/nzbget/nzbget -O
KillMode=process
Restart=on-failure
 
[Install]
WantedBy=multi-user.target
1 Like

Thanks very much @eekfonky! Using your examples I was able to get the external USB drive mounted before Nzbget starts and the service starts up on boot now.

Struggled a bit at first with not umounting the OSMC mount first, typos like no ‘/’ in front of ‘mnt/extHD’ and ‘ntfs’ has to be lowercase. Once those were sorted out everything worked as you promised.

Wouldn’t have been able to figure it out without your help, so thanks again for your contributions and taking the time to respond and help out!

-stevewk

1 Like

Happy to help! I’m always asking questions on forums and I like to give back when I can

1 Like