在 Ubuntu 中,
我做过谷歌和 IRC。我找不到答案。也许Ubuntu中不存在这样的命令。一开始,我认为所有自动启动的服务都会在 下/etc/rc2.d/,但我错了。有些只在/etc/init/*.conf. 然后我尝试了该chkconfig工具(手动安装),但它始终不起作用。例如,它给出了mongodb从 自动启动的错误结果/etc/init/mongodb.conf。
service --status-all并且initctl list只能告诉服务的当前状态而不是自动启动状态。update-rc.d是更改自动启动状态而不是显示状态的命令。
如果我的问题没有答案,我只是想知道为什么在 Ubuntu 中检查自动启动服务如此困难。
小智 11
Ubuntu 使用Upstart代替传统的init系统。Upstart 比 init 强,但比init.
相比之下,新贵是基于事件的。“事件”可以是“启动”之类的东西……或者它可以更具体,例如“网络现在可以使用了”。您可以指定哪些脚本取决于哪些事件。只要有可用的 CPU,任何不等待事件的东西都可以运行。
这种基于事件的系统还有另一个优势:理论上即使在系统启动并运行之后,您也可以使用它。Upstart 最终将接管一些任务,例如或插入外部设备,如拇指驱动器(目前由 udev 和 hal 处理),或在特定时间运行程序(目前由 cron 处理)。
正如您现在应该知道的那样,一个死的守护进程(不在启动时运行)可能因为事件而活着并启动。
Ubuntu 有用于 Upstart 的 /etc/init 和用于旧 SysV 文件的 /etc/init.d。其中的一些文件是尚未迁移的常规 SysV Init 脚本。但是一些已迁移的服务维护着从 /etc/init.d 到 /lib/init/upstart-job 的链接。如果您运行其中一个,它可以工作,但它首先会打印警告:
与其通过 /etc/init.d 调用 init 脚本,不如使用 service(8) 实用程序,例如
service mysql restart由于您尝试调用的脚本已转换为 Upstart 作业,您还可以使用 restart(8) 实用程序,例如重新启动 mysql。
在 Upstart 机器上,init 来自 upstart。Upstart 的 init 不是运行一个主 rc 脚本来调用特定运行级别的脚本,而是从其作业目录中获取作业。
现在我们知道没有简单的方法可以列出自动启动守护程序,您应该列出所有守护程序并一一检查它们。守护进程可以由init或 由upstart或什至由稍后的事件启动。
获取此列表的最简单方法是在 shell 中运行此命令:
initctl show-config
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
...
hostname
start on startup
udevtrigger
start on ((startup and started udev) and not-container)
tty2
start on (runlevel [23] and ((not-container or container CONTAINER=lxc) or container CONTAINER=lxc-libvirt))
...
Run Code Online (Sandbox Code Playgroud)
像第一个这样的项目很简单,hostname在启动时开始。但其他项目可能看起来更复杂。(但幸运的是人类可读:-))
实际上,所有服务都只存在于 /etc/init.d 下:
rc0.d contains the services which runs in runlevel 0
rc1.d contains the services which runs in runlevel 1
rc2.d contains the services which runs in runlevel 2
rc3.d contains the services which runs in runlevel 3
rc4.d contains the services which runs in runlevel 4
rc5.d contains the services which runs in runlevel 5
rc6.d contains the services which runs in runlevel 6
Run Code Online (Sandbox Code Playgroud)
还有一件事,所有的服务都存在于rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d也,但它只是一个符号链接/etc/init.d而已。
看到这里这是rc1.d目录的内容:
lrwxrwxrwx 1 root root 20 Aug 17 14:54 K15pulseaudio -> ../init.d/pulseaudio
lrwxrwxrwx 1 root root 22 Nov 28 18:47 K20acpi-support -> ../init.d/acpi-support
lrwxrwxrwx 1 root root 20 Aug 17 14:54 K20kerneloops -> ../init.d/kerneloops
lrwxrwxrwx 1 root root 23 Nov 7 15:24 K20openbsd-inetd -> ../init.d/openbsd-inetd
lrwxrwxrwx 1 root root 15 Aug 17 14:54 K20saned -> ../init.d/saned
lrwxrwxrwx 1 root root 27 Aug 17 14:54 K20speech-dispatcher -> ../init.d/speech-dispatcher
-rw-r--r-- 1 root root 369 Apr 14 2012 README
lrwxrwxrwx 1 root root 19 Aug 17 14:54 S30killprocs -> ../init.d/killprocs
lrwxrwxrwx 1 root root 19 Aug 17 14:54 S70dns-clean -> ../init.d/dns-clean
Run Code Online (Sandbox Code Playgroud)
在这里您可以观察到 init.d 的符号链接(K15pulseaudio -> ../init.d/pulseaudio)。
但是这里每个服务都链接到 init.d,对吗?但是每个服务都不会启动;原因是两个脚本。
第一个是S脚本(S30killprocs)--->开始
第二个是k脚本(K15pulseaudio)--->kill
所有 K 脚本服务终止服务,所有 S 脚本服务启动该运行级别的服务。
简单来说
S70dns-clean -> ../init.d/dns-cleandns-clean在运行级别 1 中启动服务。
K15pulseaudio -> ../init.d/pulseaudiopulseaudio在运行级别 1 中终止服务。
| 归档时间: |
|
| 查看次数: |
64054 次 |
| 最近记录: |