On Ubuntu 22.04 server, I have a bash script that reloads nagios4 config. After the reload I would like to check if the service is fine
#!/bin/bash sudo systemctl reload nagios4.service if (systemctl --quiet is-failed nagios4.service); then echo "Bad config!" fi somehow it's not working, if the config is not ok, the service fails but this is not recognized by systemctl is-failed
if manually I check systemctl status nagios4
× nagios4.service - nagios4 Loaded: loaded (/lib/systemd/system/nagios4.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Wed 2024-06-05 09:20:03 CEST; 4min 27s ago I have tried to change my script to use restart instead of reload or to run systemctl is-failed with sudo, but nothing changes.
What am I missing?
Update: reload return status is 0 even on failure
sudo systemctl reload nagios4.service status=$? echo $status
reloadcommand is.reloadhas return code0