Nagios "started" then "deactivated", systemd spec wrong?

Attempting to start nagios fails strangely, it appears to succeed, then “deactivates”. Why would it do that? it’s supposed to stay running…

+ systemctl status nagios                                                                                                                                                                                           
? nagios.service - Network Monitor Nagios
     Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; preset: disabled)
     Active: inactive (dead) since Wed 2024-12-11 23:58:34 CST; 2min 47s ago
   Duration: 153ms
 Invocation: c1f21a5eb44e426bbc0a3155d6a3a8ae
    Process: 37833 ExecStartPre=/usr/sbin/nagios -v /etc/nagios/nagios.cfg (code=exited, status=0/SUCCESS)
    Process: 37834 ExecStart=/usr/sbin/nagios -d /etc/nagios/nagios.cfg (code=exited, status=0/SUCCESS)
    Process: 37839 ExecStopPost=/usr/bin/rm -f /var/spool/nagios/nagios.cmd (code=exited, status=0/SUCCESS)
   Main PID: 37834 (code=exited, status=0/SUCCESS)
        CPU: 328ms
 
Dec 11 23:58:33 v158 nagios[37833]:         Checked 0 host dependencies
Dec 11 23:58:33 v158 nagios[37833]:         Checked 5 timeperiods
Dec 11 23:58:33 v158 nagios[37833]: Checking global event handlers...
Dec 11 23:58:33 v158 nagios[37833]: Checking obsessive compulsive processor commands...
Dec 11 23:58:33 v158 nagios[37833]: Checking misc settings...
Dec 11 23:58:33 v158 nagios[37833]: Total Warnings: 0
Dec 11 23:58:33 v158 nagios[37833]: Total Errors:   0
Dec 11 23:58:33 v158 nagios[37833]: Things look okay - No serious problems were detected during the pre-flight check
Dec 11 23:58:33 v158 systemd[1]: Started Network Monitor Nagios.
Dec 11 23:58:34 v158 systemd[1]: nagios.service: Deactivated successfully.
+ systemctl start nagios
+ journalctl '-S9 sec ago'
Dec 12 00:01:21 v158 systemd[1]: Starting Network Monitor Nagios...
Dec 12 00:01:21 v158 nagios[37901]: Nagios Core 4.5.4
Dec 12 00:01:21 v158 nagios[37901]: Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Dec 12 00:01:21 v158 nagios[37901]: Copyright (c) 1999-2009 Ethan Galstad
Dec 12 00:01:21 v158 nagios[37901]: Last Modified: 2024-08-14
Dec 12 00:01:21 v158 nagios[37901]: License: GPL
Dec 12 00:01:21 v158 nagios[37901]: Website: https://www.nagios.org
Dec 12 00:01:21 v158 nagios[37901]: Reading configuration data...
Dec 12 00:01:21 v158 nagios[37901]:    Read main config file okay...
Dec 12 00:01:21 v158 nagios[37901]:    Read object config files okay...
Dec 12 00:01:21 v158 nagios[37901]: Running pre-flight check on configuration data...
Dec 12 00:01:21 v158 nagios[37901]: Checking objects...
Dec 12 00:01:21 v158 nagios[37901]:         Checked 159 services.
Dec 12 00:01:21 v158 nagios[37901]:         Checked 27 hosts.
Dec 12 00:01:21 v158 nagios[37901]:         Checked 2 host groups.
Dec 12 00:01:21 v158 nagios[37901]:         Checked 0 service groups.
Dec 12 00:01:21 v158 nagios[37901]:         Checked 6 contacts.
Dec 12 00:01:21 v158 nagios[37901]:         Checked 3 contact groups.
Dec 12 00:01:21 v158 nagios[37901]:         Checked 21 commands.
Dec 12 00:01:21 v158 nagios[37901]:         Checked 5 time periods.
Dec 12 00:01:21 v158 nagios[37901]:         Checked 0 host escalations.
Dec 12 00:01:21 v158 nagios[37901]:         Checked 0 service escalations.
Dec 12 00:01:21 v158 nagios[37901]: Checking for circular paths...
Dec 12 00:01:21 v158 nagios[37901]:         Checked 27 hosts
Dec 12 00:01:21 v158 nagios[37901]:         Checked 0 service dependencies
Dec 12 00:01:21 v158 nagios[37901]:         Checked 0 host dependencies
Dec 12 00:01:21 v158 nagios[37901]:         Checked 5 timeperiods
Dec 12 00:01:21 v158 nagios[37901]: Checking global event handlers...
Dec 12 00:01:21 v158 nagios[37901]: Checking obsessive compulsive processor commands...
Dec 12 00:01:21 v158 nagios[37901]: Checking misc settings...
Dec 12 00:01:21 v158 nagios[37901]: Total Warnings: 0
Dec 12 00:01:21 v158 nagios[37901]: Total Errors:   0
Dec 12 00:01:21 v158 nagios[37901]: Things look okay - No serious problems were detected during the pre-flight check
Dec 12 00:01:21 v158 systemd[1]: Started Network Monitor Nagios.
Dec 12 00:01:21 v158 systemd[1]: nagios.service: Deactivated successfully.

Offhand i’d guess the systemd spec file needs to be tweaked to leave it running?

openSUSE-release|20241210-3262.1
nagios|4.5.4-1.2

/usr/lib/systemd/system/nagios.service:

[Unit]
Description=Network Monitor Nagios
After=syslog.target network.target
 
[Service]
# for details of the additional system hardening configuration please see
# https://en.opensuse.org/openSUSE:Security_Features#Systemd_hardening_effort
ProtectSystem=full
ProtectHome=true
ProtectHostname=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
RestrictRealtime=true
# end of system hardening
ExecStartPre=/usr/sbin/nagios -v /etc/nagios/nagios.cfg
ExecStart=/usr/sbin/nagios -d /etc/nagios/nagios.cfg
ExecStopPost=/usr/bin/rm -f /var/spool/nagios/nagios.cmd
ExecReload=/usr/sbin/nagios -v /etc/nagios/nagios.cfg
ExecReload=kill -HUP $MAINPID
 
[Install]
WantedBy=multi-user.target
Alias=monitoring_daemon.service

So, nagios process decided to exit. Check its log why.

1 Like

nagios logfile exists and empty, nothing relevant in journalctl other than as above.

@gregrwm I would suggest a systemctl edit nagios.service to create an override config and comment out the hardening effort lines. See if that helps the service start, if so, add each back in one at a time until you find the offending entry(ies), then a bug report to get the service fixed…

1 Like

found this unit file from nagios:

[Unit]
Description=Nagios
BindTo=network.target

[Service]
Type=simple
User=nagios
Group=nagios
ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg

[Install]
WantedBy=multi-user.target

i mixed and matched and tried this:

[Unit]
Description=Nagios
After=syslog.target network.target

[Service]
# for details of the additional system hardening configuration please see
# https://en.opensuse.org/openSUSE:Security_Features#Systemd_hardening_effort
ProtectSystem=full
ProtectHome=true
ProtectHostname=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=true
RestrictRealtime=true
# end of system hardening
Type=simple
User=nagios
Group=nagios
ExecStart=/usr/sbin/nagios /etc/nagios/nagios.cfg

[Install]
WantedBy=multi-user.target

and got this result:

+ systemctl status nagios                                                                                                                                                                                           
? nagios.service - Nagios
     Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; preset: disabled)
     Active: inactive (dead) since Thu 2024-12-12 01:42:09 CST; 8min ago
   Duration: 81ms
 Invocation: 2e4720089d8c4bb1b65a8b27e0cdb40d
   Main PID: 38330 (code=exited, status=0/SUCCESS)
        CPU: 201ms
 
Dec 12 01:42:09 v158 nagios[38329]:         Checked 0 host dependencies
Dec 12 01:42:09 v158 nagios[38329]:         Checked 5 timeperiods
Dec 12 01:42:09 v158 nagios[38329]: Checking global event handlers...
Dec 12 01:42:09 v158 nagios[38329]: Checking obsessive compulsive processor commands...
Dec 12 01:42:09 v158 nagios[38329]: Checking misc settings...
Dec 12 01:42:09 v158 nagios[38329]: Total Warnings: 0
Dec 12 01:42:09 v158 nagios[38329]: Total Errors:   0
Dec 12 01:42:09 v158 nagios[38329]: Things look okay - No serious problems were detected during the pre-flight check
Dec 12 01:42:09 v158 systemd[1]: Started Network Monitor Nagios.
Dec 12 01:42:09 v158 systemd[1]: nagios.service: Deactivated successfully.
+ systemctl start nagios
+ sleep 3
+ journalctl '-S9 sec ago'
Dec 12 01:50:48 v158 systemd[1]: Started Nagios.
Dec 12 01:50:48 v158 nagios[38483]: Nagios 4.5.4 starting... (PID=38483)
Dec 12 01:50:48 v158 nagios[38483]: Nagios Core 4.5.4
Dec 12 01:50:48 v158 nagios[38483]: Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Dec 12 01:50:48 v158 nagios[38483]: Copyright (c) 1999-2009 Ethan Galstad
Dec 12 01:50:48 v158 nagios[38483]: Last Modified: 2024-08-14
Dec 12 01:50:48 v158 nagios[38483]: License: GPL
Dec 12 01:50:48 v158 nagios[38483]: Website: https://www.nagios.org
Dec 12 01:50:48 v158 nagios[38483]: Nagios 4.5.4 starting... (PID=38483)
Dec 12 01:50:48 v158 nagios[38483]: Local time is Thu Dec 12 01:50:48 CST 2024
Dec 12 01:50:48 v158 nagios[38483]: qh: Failed to init socket '/var/lib/nagios/rw/nagios.qh'. bind() failed: No such file or directory
Dec 12 01:50:48 v158 nagios[38483]: Error: Failed to initialize query handler. Aborting
Dec 12 01:50:48 v158 nagios[38483]: Local time is Thu Dec 12 01:50:48 CST 2024
Dec 12 01:50:48 v158 nagios[38483]: LOG VERSION: 2.0
Dec 12 01:50:48 v158 nagios[38483]: qh: Failed to init socket '/var/lib/nagios/rw/nagios.qh'. bind() failed: No such file or directory
Dec 12 01:50:48 v158 nagios[38483]: Error: Failed to initialize query handler. Aborting
Dec 12 01:50:48 v158 systemd[1]: nagios.service: Main process exited, code=exited, status=1/FAILURE
Dec 12 01:50:48 v158 systemd[1]: nagios.service: Failed with result 'exit-code'.

Looks like still more packaging difficulty? First google result matching that is an error that was fixed in 2013…Still looking, suggestions welcome…

@gregrwm does /var/lib/nagios/rw exist, is it owned by nagios:nagios? I’m assuming the system-user-nagios package is installed?

1 Like

system-user-nagios is installed.

drwxrwxr-x 1 nagios nagcmd      0 2024-08-15 Thu 10:46:35 /var/lib/nagios/

…exists and is empty.

Hi, what is the output of # systemctl list-units --type=service --state=failed

1 Like

@gregrwm and if you create it and then chown nagios:nagcmd then restart the service.

1 Like

@gregrwm So that’s a bug if creating the directory etc worked…

See 1234612 – nagios install doesn't create /var/lib/nagios/rw and thus won't start

1 Like

@gregrwm If you test the list of hardening options to see what ones stop nagios working, that will help the bug owner.

1 Like

none of them. see the bug.

@gregrwm ahh you added the reload?

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

indeed the reload is handy, but the critical changes are “Type=simple” and the modified “ExecStart”.

So actually the whole solution is to create /var/lib/nagios/rw and chown nagios:nagcmd as you suggested above, and revise /usr/lib/systemd/system/nagios.service, as reported in the bug.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.