13

How do I find out which commands are applicable for a service with systemctl?

# systemctl reload nagios.service
failed to reload nagios.service: Job type reload is not applicable for unit nagios.service.

With init.d you could run the script without command and see the usage info for applicable commands:

# /etc/init.d/nagios 
Usage: /etc/init.d/nagios {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}

1 Answer 1

14
+50

systemctl is not like the good old init-scripts. According to its man page and its source code, it supports the following commands that are like the init-script commands you are searching for:

  • start Start (activate) one or more units specified on the command line.
  • stop Stop (deactivate) one or more units specified on the command line.
  • reload Asks all units listed on the command line to reload their configuration.
  • restart Stop and then start one or more units specified on the command line. If the units are not running yet, they will be started.
  • try-restart Stop and then start one or more units specified on the command line if the units are running. This does nothing if units are not running.
  • reload-or-restart Reload one or more units if they support it. If not, stop and then start them instead. If the units are not running yet, they will be started.
  • try-reload-or-restart Reload one or more units if they support it. If not, stop and then start them instead. This does nothing if the units are not running.

The following redundant aliases exist, mostly for legacy reasons:

Verb Aliases
try-reload-or-restart reload-or-try-restart, condreload, force-reload
try-restart condrestart
stop condstop

So the group of these commands comes down to start, stop and reload. Since start and stop are necessary for most service types (and you normally know if a service does not support one of them), the only thing you could want to know about is if a given service supports reload or not.

Most times, you want it to either reload or restart: use systemctl reload-or-restart nagios then. To really find out what command (if any) is executed for reloading, you can look into its service file. This can usually be found in /lib/systemd/system/ or /usr/lib/systemd/system and is named $SERVICENAME.service (in your case nagios.service). This file contains commands for starting, stopping and maybe reloading the service, namely ExecStart, ExecStop and ExecReload. If you're interested in that, you could do a grep ExecReload /lib/systemd/system/nagios.service to find out if a service supports reloading or not.

As @LucaRicci pointed out, more elaborate services can have a ReloadSignal instead of the ExecReload, which they will answer to via sd_notify to indicate success.

TL;DR

systemctl essentially supports start, stop and reload. To find out if a Service supports reloading, just try it. If you need to reload multiple services in a script or something, use reload-or-restart, which reloads the service if it has an ExecReload-command or ReloadSignal stored, otherwise it restarts it.

5
  • Thank you! "reload-or-restart" is really useful to know.
    – Lerkes
    Feb 13, 2016 at 16:18
  • @Mitja could you enhance your already great answer by confirming that reload on a stopped service won't start it; and what about reload-or-restart on a stopped service?
    – 4wk_
    Jul 27, 2022 at 13:21
  • 1
    @4wk_ you probably want try-reload-or-restart PATTERN... According to manpage: " Reload one or more units if they support it. If not, stop and then start them instead. This does nothing if the units are not running."
    – nhed
    Oct 26, 2022 at 1:03
  • What about Type=notify-reload services? They don't have ExecReload but send ReloadSignal (or SIGHUP) to the main process...
    – Luca Ricci
    Sep 21, 2023 at 12:35
  • @LucaRicci If I understand the man page correctly, such a service must call sd_notify() with RELOADING=1 to signal that it processes the reload command. I added that to the answer, thanks.
    – Mitja
    Sep 22, 2023 at 16:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .