#998045 nagios4-common: PID file is not being created

#998045#5
Date:
2021-10-29 00:58:48 UTC
From:
To:
Dear Maintainer, the current systemd service unit for Nagios 4 (/lib/systemd/system/nagios4.service) doesn't allow Nagios to create its PID file because Nagios is not running in daemon mode (option -d is missing) and Nagios (apparently) only creates its PID file ('lock_file' option in /etc/nagios4/nagios.cfg) when it runs in daemon mode.

In addition, the default PID file name in the service unit (PIDFile=/run/nagios4/nagios.pid) is different that the one in /etc/nagios4/nagios.cfg (lock_file=/var/run/nagios4/nagios4.pid), so it might be a good idea to fix that inconsistency as well.

Now, and just for reference, I've created the following systemd drop-in as a workaround, /etc/systemd/system/nagios4.service.d/10-fix-for-incorrect-pid-management.conf:

[Service]
ExecStartPost=/bin/sh -c 'umask 022; pgrep nagios4 > /var/run/nagios4/nagios4.pid'
PIDFile=/run/nagios4/nagios4.pid

But maybe that approach wouldn't be really appropriate for the fix and instead, it would be preferred to run Nagios in daemon mode as you can see upstream. From https://github.com/NagiosEnterprises/nagioscore/blob/master/startup/default-service.in:

ExecStart=@bindir@/nagios -d @sysconfdir@/nagios.cfg

#998045#10
Date:
2021-10-30 01:18:28 UTC
From:
To:
My previous systemd drop-in workaround was incomplete. This is the complete
version of
/etc/systemd/system/nagios4.service.d/10-fix-for-incorrect-pid-management.conf:

[Service]
ExecStartPost=/bin/sh -c 'umask 022; pgrep nagios4 >
/var/run/nagios4/nagios4.pid'
RuntimeDirectory=nagios4
PIDFile=/run/nagios4/nagios4.pid

Where RuntimeDirectory=nagios4 is required for /var/run/nagios4 to be
automatically created.