207

Is there a command to list services that run on startup? I imagine it would involve parsing /etc/init.d/, and the various /etc/rc.* directories.

Mahdi
  • 1,482
Eric H
  • 2,173

10 Answers10

204

The quick answer is: It depends on your init system.

The long answer is: For current versions of Ubuntu, you probably have a mix of Upstart, and SystemV. Newer versions of Ubuntu after 15.04 "Vivid Vervet" (and other Linux distros like RHEL/CentOS 7) are moving to use SystemD.

Upstart

To list all services:

sudo initctl list

To list all Upstart services and run initctl show-config on them, this one-liner may be helpful:

sudo initctl list | awk '{ print $1 }' | xargs -n1 initctl show-config

System V

To list all services:

sudo service --status-all

OR:

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

for runlevel symlinks:

ls /etc/rc*.d/

SystemD

To list all services:

sudo systemctl --all list-unit-files --type=service

OR:

ls /lib/systemd/system/*.service /etc/systemd/system/*.service
Akhil
  • 646
TrinitronX
  • 3,394
114

You can simply use the initctl list shell command to list the contents of /etc/init rather than the suggested dbus-send command.

BuZZ-dEE
  • 14,533
Scott
  • 1,324
16

For Ubuntu 18.04 use :

systemctl list-units --type=service

instead of initctl.

Since Ubuntu 16.04, initctl has been replaced by systemd (source, in French).

If it can help @sanjay-manohar.

Pablo Bianchi
  • 17,371
AppyGG
  • 273
13

The /etc/init.d and /etc/rc.* directories have been superseded by the 'upstart' init tool. Although scripts in these directories will be executed as expected, the new method for running things on init is defined by files in /etc/init/

You can list all of the upstart jobs with by querying upstart over dbus:

dbus-send --print-reply --system --dest=com.ubuntu.Upstart \
        /com/ubuntu/Upstart com.ubuntu.Upstart0_6.GetAllJobs

You may have to change 0_6 to reflect the version of upstart you have. This command works on my lucid install.

BuZZ-dEE
  • 14,533
Jeremy Kerr
  • 27,829
12

If you want a nice graphical representation of services and time it takes to boot try:

sudo apt install bootchart

For systemd (since 16.04) try systemd-bootchart instead:

sudo apt install systemd-bootchart
Pablo Bianchi
  • 17,371
11

Id use initctl show-config <servicename> to really get the details of when/if your service will start during boot.

Like so:

$ initctl show-config myservice
myservice
  start on runlevel [2345]
  stop on runlevel [!2345]

Or for NFS4 idmap-daemon:

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

chkconfig is only preferable on RedHat based systems imho.

CBmemnon
  • 111
9

On 12.04 we could use:

sudo apt-get install chkconfig
chkconfig --list

but it was removed in 12.10.

Sample output:

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
5

Besides system services and scripts under:

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

There are probably AutoStart Applications too, for example:

find / -name "*autostart*"

ls -1 "/etc/xdg/autostart" "/home/$USER/.config/autostart" "/usr/share/gdm/autostart"  "/usr/share/gnome/autostart"
Noam Manos
  • 379
  • 5
  • 9
1

With systemd, which we have had since 16.04, we can use the analyzer which shows what started in the order it started, which is way more practical.

systemd-analyze plot > SystemdAnalyzePlot.svg
gimp SystemdAnalyzePlot.svg

If you prefer a text based visualization (or you're using ssh) then use the dump function instead:

systemd-analyze dump | less

This is extremely detailed with the .service data shown for each unit started.

As mentioned above, you can get a list of all the units with a command such as:

systemctl list-units --type=service

The list is good to see which units failed to start if you have such a problem.

Alexis Wilke
  • 2,787
-1

Using 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)}}'

Sample output:

$ 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
muru
  • 207,228