Systemctl: find out which commands are applicable for a service
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}
Solution 1:
systemctl
is not like the good old init-scripts. According to its man
page, 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
Restart one or more units specified on the command line. If the units are not running yet, they will be started. -
try-restart
Restart one or more units specified on the command line if the units are running. This does nothing if units are not running. Note that, for compatibility with Red Hat init scripts,condrestart
is equivalent to this command. -
reload-or-restart
Reload one or more units if they support it. If not, restart them instead. If the units are not running yet, they will be started. -
reload-or-try-restart
Reload one or more units if they support it. If not, restart them instead. This does nothing if the units are not running. Note that, for compatibility with SysV init scripts,force-reload
is equivalent to this command.
So the group of these commands essentially boils 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.
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 stored, otherwise it restarts it.