Command to list services that start on startup?

403,256

Solution 1

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

Solution 2

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

Solution 3

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.

Solution 4

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.

Solution 5

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.

Share:
403,256

Related videos on Youtube

Tomasz Tybulewicz
Author by

Tomasz Tybulewicz

Updated on September 17, 2022

Comments

  • Tomasz Tybulewicz
    Tomasz Tybulewicz over 1 year

    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.

  • Jeremy Kerr
    Jeremy Kerr about 13 years
    @Eric H: Could your set the answer below as correct instead - initctl list is much nicer than this dbus command. I'd like to leave this answer here for reference (rather than deleting it completely) though.
  • A.B.
    A.B. about 9 years
    Doesn't work in Ubuntu. packages.ubuntu.com/…
  • Ciro Santilli OurBigBook.com
    Ciro Santilli OurBigBook.com about 9 years
    @A.B. thanks for letting me know! It is rare for downvoters to comment nowadays: it requires courage and allows me to learn. updated with the version it works in.
  • Ciro Santilli OurBigBook.com
    Ciro Santilli OurBigBook.com about 9 years
  • Cerin
    Cerin over 7 years
    This is the correct answer. I have no idea why all the wrong and incomplete answers are so highly upvoted.
  • sjas
    sjas over 7 years
    This should be the accepted answer.
  • Gabriel Netto
    Gabriel Netto over 7 years
    This doenst work for people using SysV, I agree this it a good answer but it is incomplete.
  • Wildcard
    Wildcard about 5 years
    service --status-all does NOT show whether services are enabled to start on boot, at least not on Ubuntu 16. It shows whether services are currently running or not.
  • Phlucious
    Phlucious almost 5 years
    I had to sudo service --status-all to get all of the services to show up. A few were hidden when I only ran service --status-all on a non-root account.
  • Ben Middleton
    Ben Middleton almost 5 years
    @Phlucious : Thanks for mentioning that. I assumed it was well known that these commands are usually run as root (systemctl, service, initctl...) as they are usually considered system administration commands.
  • Sanjay Manohar
    Sanjay Manohar almost 5 years
    Does this work in Ubuntu 18.04? I get "initctl: command not found" (in bash)
  • Rémy Hosseinkhan Boucher
    Rémy Hosseinkhan Boucher over 4 years
    initctl list does not found on Ubuntu 19.10
  • AppyGG
    AppyGG about 4 years
    @RémyHosseinkhanBoucher For more recent version of Ubuntu askubuntu.com/a/1167921/988056
  • Arun
    Arun almost 4 years
    service --status-all This command worked in my debian box too
  • Pablo Bianchi
    Pablo Bianchi over 2 years
    The OP asked for services starting on startup, so you need the --state enabled bit to systemctl. And as man page state service --status-all will return if they are running or not, not if they are set to run on startup