有没有一个命令可以列出在启动时运行的服务?我想这可能涉及解析"/etc/init.d/"和各个"/etc/rc.*"目录。
init
系统。要列出所有服务:
sudo initctl list
initctl show-config
,这个一行命令可能会有帮助:sudo initctl list | awk '{ print $1 }' | xargs -n1 initctl show-config
列出所有服务:
sudo service --status-all
或:
# for init scripts:
ls /etc/init.d/
# for runlevel symlinks:
ls /etc/rc*.d/
列出所有服务:
sudo systemctl --all list-unit-files --type=service
或者:
ls /lib/systemd/system/*.service /etc/systemd/system/*.service
initctl list
命令来列出/etc/init
的内容,而不是建议的dbus-send
命令。initctl list
命令。 - Rémy Hosseinkhan Bouchersystemctl list-units --type=service
而不是使用initctl
。
自Ubuntu 16.04起,initctl
已被systemd
取代(来源,法文)。
如果可以的话帮助@sanjay-manohar。
dbus-send --print-reply --system --dest=com.ubuntu.Upstart \
/com/ubuntu/Upstart com.ubuntu.Upstart0_6.GetAllJobs
0_6
更改为您拥有的upstart版本。这个命令适用于我安装的lucid版本。initctl list
比这个dbus命令要好得多。虽然我想保留这个答案供参考(而不是完全删除它)。 - Jeremy Kerrsudo apt install bootchart
对于systemd(自16.04开始),请尝试使用 systemd-bootchart:
sudo apt install systemd-bootchart
initctl show-config <servicename>
来真正了解您的服务在启动过程中何时/是否启动。$ initctl show-config myservice
myservice
start on runlevel [2345]
stop on runlevel [!2345]
$ initctl show-config idmapd
idmapd
start on (local-filesystems or mounting TYPE=nfs4)
stop on runlevel [06]
sudo apt-get install chkconfig
chkconfig --list
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
可能还有一些自启动应用程序,例如:/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"
使用gawk:
ls -l /etc/rc*.d/* | gawk 'match($0, /rc([0-6S]).d.*\/(.*)$/, a) {l[a[2]]=l[a[2]]a[1]","}; END{for(v in l){print v,substr(l[v],1,length(l[v])-1)}}'
$ ls -l /etc/rc*.d/* | gawk 'match($0, /rc([0-6S]).d.*\/(.*)$/, a) {l[a[2]]=l[a[2]]a[1]","}; END{for(v in l){print v,substr(l[v],1,length(l[v])-1)}}' | egrep README
README 0,1,2,3,4,5,6,S
service --status-all
不会显示服务是否已启用以在启动时运行,至少在Ubuntu 16上不会。它显示服务当前是否正在运行。 - Wildcardsudo service --status-all
命令才能显示出所有的服务。当我在非root账户上运行service --status-all
命令时,有几个服务是隐藏的。 - Phlucioussystemctl
,service
,initctl
...),因为它们通常被视为系统管理命令。 - TrinitronXservice --status-all
这个命令在我的debian
系统上也起作用。 - Arun--state enabled
参数来执行systemctl命令。而且根据man页面,service --status-all
命令返回服务是否正在运行,而不是它们是否设置为在启动时运行。 - Pablo Bianchi