Systemd startup scripts for Sonarr and Nzbget

osmc@osmc:~$ systemctl status sonarr.service
* sonarr.service - Sonarr Daemon
   Loaded: loaded (/etc/systemd/system/sonarr.service; enabled)
   Active: failed (Result: exit-code) since Sat 2015-04-11 09:02:47 UTC; 3min 27s ago
  Process: 230 ExecStart=/usr/bin/mono /opt/NzbDrone/NzbDrone.exe (code=exited, status=2)
 Main PID: 230 (code=exited, status=2)

osmc@osmc:~$ systemctl status nzbget.service
* nzbget.service - NZBGet
   Loaded: loaded (/etc/systemd/system/nzbget.service; enabled)
   Active: failed (Result: exit-code) since Sat 2015-04-11 09:02:46 UTC; 3min 45s ago
  Process: 250 ExecStop=/usr/bin/nzbget -Q (code=exited, status=203/EXEC)
  Process: 228 ExecStart=/usr/bin/nzbget -D (code=exited, status=203/EXEC)
 Main PID: 228 (code=exited, status=203/EXEC)

Can anyone help as to why these are happening?

/etc/systemd/system/sonarr.service

[Unit]
Description=Sonarr Daemon
After=syslog.target network-online.target

[Service]
User=osmc
Group=osmc

Type=simple
ExecStart=/usr/bin/mono /opt/NzbDrone/NzbDrone.exe
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target

/etc/systemd/system/nzbget.service

[Unit]
Description=NZBGet
# This will load nzbget only after setting up the network
After=network-online.target
[Service]
User=osmc
ExecStart=/usr/bin/nzbget -D
ExecStop=/usr/bin/nzbget -Q
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
[Install]
# Needed to run nzbget at boot
WantedBy=multi-user.target

These are the scripts above

â—Ź nzbget.service - NZBGet
  Loaded: loaded (/etc/systemd/system/nzbget.service; enabled)
  Active: inactive (dead) since Sat 2015-07-04 16:23:29 BST; 5min ago
  Process: 291 ExecStop=/opt/nzbget/nzbget -Q (code=exited, status=0/SUCCESS)
  Process: 240 ExecStart=/opt/nzbget/nzbget -D (code=exited, status=0/SUCCESS)
  Main PID: 240 (code=exited, status=0/SUCCESS)

Is what I’m getting now. I have managed to get Sonarr to work as a .service under systemd. I had forgotten to enable it via sudo systemctl enable sonarr. Any suggestions as to how to get NzbGet to run?

bit of a dead thread maybe, but in the unit section add

Type=forking

then sudo systemctl daemon-reload

OK got them both working, see below:

NZBGet;

[Unit]
Description=NZBGet Daemon
After=network.target
RequiresMountsFor=/mnt/ #or whatever your mountpoint is

[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

Sonarr;

[Unit]
Description=Sonarr Daemon
After=syslog.target network.target

[Service]
User=osmc
Group=osmc

Type=simple
ExecStart=/usr/bin/mono /opt/NzbDrone/NzbDrone.exe --nobrowser
TimeoutStopSec=20
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target

These both work well, tested today on RPi 2 & RPi3

Hey Everybody,
I’m fighting against NZBGet since 2 days… I reed every tuto, forum, i can’t find my mistake !

I installed successfully NZBGet but I completely lost with the autostart on my raspberry pi… I tried to add a Crontab, I tried the script from @eekfonky, I tried to add a script to etc/init.d/nzbget

Anyone have an idea to help me (or to put me on the right way !..)

Thanks a lot (out of home this week-end, so i’ll read the answer, but i’ll try it until monday :slight_smile: )

As OSMC is running on Debian Jessie you’re best using the systemd folder. Put the script from above in /etc/systemd/system and name it nzbget.service. (Be carefule of the RequiresMountsFor=/mnt/ part as it’s important to use your own mount point). Now enable it with sudo systemctl enable nzbget and start it with sudo systemctl start nzbget.

You can check it’s running with sudo systemctl status nzbget if it’s not post the result here:

Hi, I’m having issues with my nzbget install…

I did a clean install of osmc and then wanted to have nzbget and sonarr to run on boot.
I installed nzbget using:
http://www.htpcguides.com/install-latest-nzbget-on-raspberry-pi-2-and-b-raspbian/

then created the systemd nzbget.service with

`[Unit]
Description=NZBGet Daemon
After=network.target
RequiresMountsFor=/media/INTENSO

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

as long as I do not reboot, nzbget works, but when I reboot, I’m getting permission issues:

`osmc@osmc:~$ sudo systemctl status nzbget

  • nzbget.service - NZBGet Daemon
    Loaded: loaded (/etc/systemd/system/nzbget.service; enabled)
    Active: inactive (dead) since Tue 2016-07-26 23:18:08 CEST; 2min 17s ago
    Process: 357 ExecStop=/opt/nzbget/nzbget -Q (code=exited, status=0/SUCCESS)
    Process: 276 ExecStart=/opt/nzbget/nzbget -c /opt/nzbget/nzbget.conf -D (code=exited, status=0/SUCCESS)

Jul 26 23:18:07 osmc nzbget[276]: nzbget.conf(70): Invalid value for option “TempDir” (/media/INTENSO/nzbget/tmp/): could not create directory /media/INTE…sion denied
Jul 26 23:18:07 osmc nzbget[276]: nzbget.conf(67): Invalid value for option “QueueDir” (/media/INTENSO/nzbget/queue/): could not create directory /media/I…sion denied
Jul 26 23:18:07 osmc nzbget[276]: nzbget.conf(61): Invalid value for option “NzbDir” (/media/INTENSO/nzbget/nzb/): could not create directory /media/INTEN…sion denied
Jul 26 23:18:08 osmc nzbget[357]: /media/INTENSO/nzbget/downloads/nzbget-2016-07-26.log: No such file or directory
Jul 26 23:18:08 osmc nzbget[357]: /media/INTENSO/nzbget/downloads/nzbget-2016-07-26.log: No such file or directory
Jul 26 23:18:08 osmc nzbget[357]: /media/INTENSO/nzbget/downloads/nzbget-2016-07-26.log: No such file or directory
Jul 26 23:18:08 osmc nzbget[357]: nzbget.conf(70): Invalid value for option “TempDir” (/media/INTENSO/nzbget/tmp/): could not create directory /media/INTE…sion denied
Jul 26 23:18:08 osmc nzbget[357]: nzbget.conf(67): Invalid value for option “QueueDir” (/media/INTENSO/nzbget/queue/): could not create directory /media/I…sion denied
Jul 26 23:18:08 osmc nzbget[357]: nzbget.conf(61): Invalid value for option “NzbDir” (/media/INTENSO/nzbget/nzb/): could not create directory /media/INTEN…sion denied
Jul 26 23:18:08 osmc nzbget[357]: Unable to send request to nzbget-server at 127.0.0.1 (port 6789)
Hint: Some lines were ellipsized, use -l to show in full.
`
it seems to be a write permission on my drive…but I’m clueless how to fix it.

any ideas?
thanks!

Have you mounted the drive in the fstab? That’s how I deal with it. If not you may need to make the service wait until the drive mounts. After the [Unit] section add in this;

[Timer]
OnBootSec=20

thanks for that!
I edited my nzbget.service and rebooted, still no joy.
I wonder if something got messed up now and I need to do a full reinstall of osmc.

I didn’t mount the drive in fstab, since osmc mounts the drive…
how can I mount the drive in fstab? do I need to deactivate osmc´s auto mounting function?

update: I found this for fstab editing:
~/dev/sdax /media/user/label type options 0 0

I’m unsure which type to use… fdisk -l shows:Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 3907024064 3907022017 1.8T 7 HPFS/NTFS/exFAT

so what type do I use?

sorry…
previous reply obviously referred to the timer line.

when starting the service after reboot manually, it tells me this:

osmc@osmc:~$ sudo systemctl enable nzbget
osmc@osmc:~$ sudo systemctl start nzbget
osmc@osmc:~$ sudo systemctl status nzbget

  • nzbget.service - NZBGet Daemon
    Loaded: loaded (/etc/systemd/system/nzbget.service; enabled)
    Active: inactive (dead) since Wed 2016-07-27 10:42:06 CEST; 8s ago
    Process: 646 ExecStop=/opt/nzbget/nzbget -Q (code=exited, status=0/SUCCESS)
    Process: 642 ExecStart=/opt/nzbget/nzbget -c /opt/nzbget/nzbget.conf -D (code=exited, status=0/SUCCESS)

Jul 27 10:42:06 osmc nzbget[646]: Unable to send request to nzbget-server at 127.0.0.1 (port 6789)

does this help?

i’ll still try to mount in fstab, my best guess is that that might help.

just a quick question on the side. I moved most nzbget directories to the external disk in the nzbget settings (when it was still working at initial install)
are there folders which I need to keep on the osmc sd-card?

OK, take out the;
[Timer]
OnBootSec=20

save and exit the file.

Please send the output of;
df -h

This will tell me what is mounted and where…lets’ not reinstall just yet! lol

too late…already reinstalled.:innocent:

I first changed the mount point from /media/INTENSO to /mnt/INTENSO.
rebooted, works…
then installed nzbget, reassigned folder paths in nzbget to the external drive, restarted nzbget, worked.
then I made and ran the system file…nzbget shut down, can’t start it anymore…
this is what it said:

osmc@osmc:~$ sudo systemctl enable nzbget
Created symlink from /etc/systemd/system/multi-user.target.wants/nzbget.service to /etc/systemd/system/nzbget.service.
osmc@osmc:~$ sudo systemctl start nzbget
osmc@osmc:~$ sudo systemctl status nzbget

  • nzbget.service - NZBGet Daemon
    Loaded: loaded (/etc/systemd/system/nzbget.service; enabled)
    Active: inactive (dead) since Wed 2016-07-27 12:13:36 CEST; 9s ago
    Process: 1319 ExecStop=/opt/nzbget/nzbget -Q (code=exited, status=0/SUCCESS)
    Process: 1315 ExecStart=/opt/nzbget/nzbget -c /opt/nzbget/nzbget.conf -D (code=exited, status=0/SUCCESS)

Jul 27 12:13:36 osmc nzbget[1319]: Request sent
Jul 27 12:13:36 osmc nzbget[1319]: server returned: Stopping server

by the way: df -h showed me this (nothing out of the ordinary I think)

osmc@osmc:~$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 362M 0 362M 0% /dev
tmpfs 367M 5.0M 362M 2% /run
/dev/mmcblk0p2 7.0G 662M 6.0G 10% /
tmpfs 367M 0 367M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 367M 0 367M 0% /sys/fs/cgroup
/dev/mmcblk0p1 240M 21M 219M 9% /boot
/dev/sda1 1.9T 668G 1.2T 36% /mnt/INTENSO
tmpfs 74M 0 74M 0% /run/user/1000

So it’s all working now then?

No. The mount worked, nzbget starts, but as soon as I start the nzbget.service, nzbget stops and cannot be restarted. Process still shows as inactive(dead).

Any ideas?

What file system is the External HD? ext4, ntfs, etc…?
Does your nzbget.service look like this?

[Unit]
Description=NZBGet Daemon
After=network.target
RequiresMountsFor=/mnt/INTENSO

[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

this is my /etc/systemd/system/nzbget.service

[Unit]
Description=NZBGet Daemon
After=network.target
RequiresMountsFor=/mnt/INTENSO #or whatever your mountpoint is

[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

Is nzbget installed in the /opt/ directory?

Try this wee guide I wrote

https://sliceopie.wikispaces.com/OSMC

yes, I installed it in /opt/…

I did notice that I left out the following:

sed -i “/DaemonUsername=/c\DaemonUsername=osmc” /opt/nzbget/nzbget.conf

entering that line afterwards didn’t solve anything…i’ll start over once more…

great guide though! everything in one spot! Thanks!!

when you do an ls -la /mnt/INTENSO
what do you get? Maybe a permission issue?