Sabnzbd: Daemon mode "-d" with systemd unit

Created on 5 May 2019  ·  9Comments  ·  Source: sabnzbd/sabnzbd

Hey guys,

just a ~quick~ (EDIT: Has gotten longer, sorry 😉) question. Usually when starting a daemon via systemd service, you do not require any GUI starts so I found the --daemon/-d option to be reasonable. But this mode causes SABnzbd to not start correctly via systemd unit.

ExecStart=/usr/bin/python2.7 -OO /etc/sabnzbd/SABnzbd.py -d -f /etc/sabnzbd/sabnzbd.ini

  • In most cases the service stops immediately, systemctl status sabnzbd just shows it as dead.
  • I am not sure if this is due to some internal process forking when using the daemon mode?
  • Sometimes it does start. Especially you can solve the immediate service stop with RemainAfterExit=true, which confirms that internal process forking is the issue. When the main process exits due to the fork, the systemd unit recognizes it as finished/dead and without the above it then stops, which prevents the internal fork.
  • But with RemainAfterExit=true and -d in most cases the web UI is not available for a long time. The process runs with low memory usage, sometimes it simply stops, sometimes it indeed forks a higher memory process after 1-2 minutes which then enables web UI access.
  • Interestingly when web UI is up one time, restarting the service immediately re-creates the web UI enabled process. But stopping the service and starting it again, or doing systemd reboot, results in having the low memory non-web-UI process for a long while.

-b 0 instead of -d instead starts up reliable and with immediate web UI access. It just uses some more memory, also more then the -d when re-forked with web UI successfully. Not sure about the internal differences or if it is even expected and desired that systemd units should run the binary without daemon mode option, as this is made for manual starts from console only?

Possibly related: https://github.com/sabnzbd/sabnzbd/issues/992

  • With auto restart options the above could indeed lead to service restart loops. The OP of that issue used --daemon first and --browser 0 finally, although this was not the only issue.

All 9 comments

just a quick question.

... and what is your quick question ... ? ;-)

But why don't you use (or: study) the PPA and its startup features, made by Linux OS guru @jcfp ? Works for me.

@sanderjo

... and what is your quick question ... ? ;-)

just a ~quick~ (EDIT: Has gotten longer, sorry 😉) question

Thanks for the suggestion, I just checked it: http://ppa.launchpad.net/jcfp/ppa/ubuntu/pool/main/s/sabnzbdplus/
It uses a sysvinit service, so not what I want to go with on modern OS.

However, as mentioned above generally I have no issue starting the daemon, as I figured out reliably working options ("-b 0"). I just wonder why the "-d/--daemon" option does not work reliable when used in systemd service and if something could be enhanced about this, if it is not intended.

I know nothing about systemd, so I can't assess this, but maybe the following is related?

https://forums.sabnzbd.org/viewtopic.php?t=23412

https://forums.sabnzbd.org/viewtopic.php?t=22320

Oh, PS: maybe you can share your systemd file so that others can learn from it?

This /etc/systemd/system/sabnzbdplus.service seems to work for me.

[Unit]
Description=the great Sabnzbd downloader
Wants=network-online.target
After=network-online.target

[Service]
User=sander
ExecStart=/usr/bin/python2.7 /usr/bin/sabnzbdplus -b0
Type=simple

[Install]
WantedBy=multi-user.target
sander@witte:~$ sudo systemctl status sabnzbdplus.service 
● sabnzbdplus.service - the great Sabnzbd downloader
   Loaded: loaded (/etc/systemd/system/sabnzbdplus.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-05-07 22:19:19 CEST; 4min 45s ago
 Main PID: 1198 (python2.7)
    Tasks: 25 (limit: 4536)
   Memory: 74.7M
   CGroup: /system.slice/sabnzbdplus.service
           └─1198 /usr/bin/python2.7 /usr/bin/sabnzbdplus -b0

image

@Safihre
Yes it does as mentioned, but why does -d/--daemon not?

Because I (with my limited Linux knowledge) think this serves 2 different purposes: the systemd one will monitor the process for you, arranging for the forking, keeping it running, status checks etc.
While the -d option SABnzbd itself takes care of the forking and kills the original process after spawning the daemon.

@Safihre
Yes it does as mentioned, but why does -d/--daemon not?

Because of Type=simple (and not forking) ?

But if that is your question, it's about systemd, not SABnzbd.

@Safihre @sanderjo
Type=forking will load forever (which makes sense when not using -d), interestingly as well with -d. So it's not really forking but yeah somehow restarting the process.

However what you say matches my thoughts that the daemon option as made for starting it as daemon from console only. I was just wondering since there are guides/examples out there that use -d in systemd units as well, which then is obviously wrong, at least with current systemd and/or SABnzbd version.

Many thanks for your answers, will mark the issue as closed.

Was this page helpful?
0 / 5 - 0 ratings