In Ubuntu, is there a command to show a list of ALL autostart services?
In Ubuntu,
- Is there a command to show a list of all autostart services?
- Is there a command to check if a service is autostarted at boot time or not?
I did Google and IRC. I can not find the answer. Maybe there no such commands exist in Ubuntu. In the beginning, I thought all autostarted services would be under /etc/rc2.d/
, but I was wrong about that. Some ones are configured only under /etc/init/*.conf
. Then I tried the chkconfig
tool (installed it manually), it does not work all the time. For instance, it gives the wrong result for mongodb
which is autostarted from /etc/init/mongodb.conf
.
service --status-all
and initctl list
can only tell the services' current status instead of autostart status. update-rc.d
is a command to change the autostart status instead of showing the status.
If there is no answer to my question, I am just wondering why it's so hard to check autostart services in Ubuntu.
Ubuntu uses Upstart
instead of the traditional init
system. Upstart is stronger than init, but it's a little bit more complicated than init
.
Upstart, in contrast, is event based. An "event" can be something like "booting" ... or it can be a lot more specific, like "the network is ready to use now". You can specify which scripts depend on which events. Anything that isn't waiting for an event can run whenever there's CPU available.
This event-based system has another advantage: you can theoretically use it even after the system is up and running. Upstart is eventually slated to take over tasks such as or plugging in external devices like thumb drives (currently handled by udev and hal), or running programs at specific times (currently handled by cron).
As you should know now, a dead daemon (that doesn't run in startup) may be alive and starts because of an event.
Ubuntu have both /etc/init, for Upstart, and /etc/init.d, for the old SysV files. Some of the files in it are regular SysV Init scripts that haven't been migrated yet. But some services that have migrated maintain a link from /etc/init.d to /lib/init/upstart-job. If you run one of those, it works, but it prints a warning first:
Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g.
service mysql restart
Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the restart(8) utility, e.g. restart mysql.
On an Upstart machine, init comes from upstart. Instead of running a master rc script that calls the scripts for a specific runlevel, Upstart's init takes jobs from its job directory.
Now we know there's no simple way to list autostart daemons, you should list all daemons and check them one by one. The daemon may be started by init
or by upstart
or even by a later event.
The simplest way to get this list is running this command in the shell:
initctl show-config
The output looks like this:
...
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))
...
Some items like the first one is so simple, hostname
starts on startup. But other items may look more complicated. (But fortunately human readable :-) )
Actually, all services are present under /etc/init.d only:
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
One more thing, all services are present under rc0.d
rc1.d
rc2.d
rc3.d
rc4.d
rc5.d
rc6.d
also, but it is a symbolic link to /etc/init.d
only.
See here this is the content of rc1.d
directory:
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
Here you can observe the symbolic link to init.d (K15pulseaudio -> ../init.d/pulseaudio).
But here every service is linked to init.d, right? But every service will not start; the reason is two scripts.
The first one is an S script (S30killprocs)---> start
The second one is a k script (K15pulseaudio)---> kill
All the K script services kill the services and all S script services start the services for that runlevel.
In brief
S70dns-clean -> ../init.d/dns-clean
start dns-clean
service in runlevel 1.
K15pulseaudio -> ../init.d/pulseaudio
kills pulseaudio
service in runlevel 1.
You can install sysv-rc-conf that is an ncurses program to configure/show the rc levels graphically.