命令列出启动时启动的服务?

Eri*_*c H 170 init.d upstart services systemd

是否有列出启动时运行的服务的命令?我想这将涉及解析/etc/init.d/和各种/etc/rc.*目录。

Tri*_*onX 165

快速回答是:这取决于您的init系统。

长答案是:对于当前版本的 Ubuntu,您可能混合使用了UpstartSystemV。15.04“Vivid Vervet”(以及其他 Linux 发行版,如 RHEL/CentOS 7)之后的较新版本的 Ubuntu 正在转向使用SystemD

暴发户

列出所有服务:

sudo initctl list
Run Code Online (Sandbox Code Playgroud)

要列出所有 Upstart 服务并initctl show-config在其上运行,此单行代码可能会有所帮助:

sudo initctl list | awk '{ print $1 }' | xargs -n1 initctl show-config
Run Code Online (Sandbox Code Playgroud)

系统五

列出所有服务:

sudo service --status-all
Run Code Online (Sandbox Code Playgroud)

或者:

# for init scripts:
ls /etc/init.d/

# for runlevel symlinks:
ls /etc/rc*.d/
Run Code Online (Sandbox Code Playgroud)

系统D

列出所有服务:

sudo systemctl list-unit-files --type=service
Run Code Online (Sandbox Code Playgroud)

或者:

ls /lib/systemd/system/*.service /etc/systemd/system/*.service
Run Code Online (Sandbox Code Playgroud)

  • 这应该是公认的答案。 (13认同)
  • `service --status-all` 不显示服务是否在启动时启动,至少在 Ubuntu 16 上不显示。它显示服务是否*当前正在运行*。 (2认同)

Sco*_*ott 114

您可以简单地使用initctl listshell 命令来列出内容/etc/init而不是建议的dbus-send命令。

  • 这在 Ubuntu 18.04 中有效吗?我得到“initctl: command not found”(在 bash 中) (9认同)
  • 在 Ubuntu 19.10 上找不到 `initctl list` (7认同)
  • @RémyHosseinkhanBoucher 有关最新版本的 Ubuntu https://askubuntu.com/a/1167921/988056 (2认同)

Jer*_*err 13

/etc/init.d/etc/rc.*目录已被“取代upstart”初始化工具。虽然这些目录中的脚本会按预期执行,但在 init 上运行东西的新方法是由文件中定义的/etc/init/

你可以通过 dbus 查询 upstart 列出所有的 upstart 工作:

dbus-send --print-reply --system --dest=com.ubuntu.Upstart \
        /com/ubuntu/Upstart com.ubuntu.Upstart0_6.GetAllJobs
Run Code Online (Sandbox Code Playgroud)

您可能需要更改0_6以反映您拥有的暴发户版本。此命令适用于我的 lucid 安装。

  • @Eric H:您能否将下面的答案设置为正确的 - `initctl list` 比这个 dbus 命令好得多。不过,我想将这个答案留在这里以供参考(而不是完全删除它)。 (3认同)

小智 12

如果您想要一个很好的服务图形表示和启动所需的时间,请尝试:

apt-get install bootchart
Run Code Online (Sandbox Code Playgroud)


小智 11

Id 用于initctl show-config <servicename>真正获取有关何时/是否在启动期间启动服务的详细信息。

像这样:

$ initctl show-config myservice
myservice
  start on runlevel [2345]
  stop on runlevel [!2345]
Run Code Online (Sandbox Code Playgroud)

或者对于 NFS4 idmap-daemon:

$ initctl show-config idmapd
idmapd
  start on (local-filesystems or mounting TYPE=nfs4)
  stop on runlevel [06]
Run Code Online (Sandbox Code Playgroud)

chkconfig 仅适用于基于 RedHat 的系统恕我直言。


App*_*yGG 11

对于 Ubuntu 18.04 使用:

systemctl list-units --type=service

代替 :

initctl

从 Ubuntu 16.04 开始,initctl已被systemd. https://www.linuxtricks.fr/wiki/systemd-les-commandes-essentielles (FR_fr)

(如果它可以帮助@sanjay-manohar)


Cir*_*郝海东 9

在 12.04 上,我们可以使用:

sudo apt-get install chkconfig
chkconfig --list
Run Code Online (Sandbox Code Playgroud)

但它在 12.10 中删除了

示例输出:

acpi-support              0:off  1:off  2:on   3:on   4:on   5:on   6:off
acpid                     0:off  1:off  2:off  3:off  4:off  5:off  6:off
apparmor                  0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on
Run Code Online (Sandbox Code Playgroud)

  • 在 Ubuntu 中不起作用。http://packages.ubuntu.com/search?suite=trusty§ion=all&amp;arch=any&amp;keywords=chkconfig&amp;searchon=names (2认同)

Noa*_*nos 5

除了以下系统服务和脚本之外:

/etc/init.d/
/lib/systemd/system/
/etc/systemd/system/

可能还有自动启动应用程序,例如:

find / -name "*autostart*"

ls -1 "/etc/xdg/autostart" "/home/$USER/.config/autostart" "/usr/share/gdm/autostart"  "/usr/share/gnome/autostart"
Run Code Online (Sandbox Code Playgroud)