大网数据广告活动
服务器运维问答

Systemctl: find out which commands are applicable for a service

· 52CE 我爱测

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…

问题原文

原帖链接 · Lerkes · CC BY-SA 3.0

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}

已采纳解答

原帖链接 · Mitja · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。