update-rc.d Cheat Sheet

update-rc.d Cheat Sheet

Get Social!

Linux penguinDebian and Ubuntu use the service command to control services and update-rc.d for adding and removing services from start up. Using the service command we can start, stop, restart and display all available services. With update-rc.d we can add and remove services and add them to the Ubuntu/ Debian start up scripts. As Linux operating systems have multiple states, or runlevels, you need to make sure you add any new services to the correct runlevels. For example, you would not want to start a web service application before starting networking.

See my post on runlevels for more information about runlevels in Linux..

What services are available for startup?

Use the status-all switch to list all services which are registered with the OS and issues them a status command. You will then get one of the following displayed next to each service:

  • [ + ] – Services with this sign are currently running.
  • [ – ] – Services with this sign are not currently running..
  • [ ? ] – Services that do not have a status switch.
service --status-all

Sample output:

service --status-all
 [ ? ] acpid
 [ - ] apparmor
 [ ? ] apport
 [ ? ] atd
 [ - ] bootlogd
 [ ? ] console-setup
 [ ? ] cron
 [ ? ] dbus
 [ ? ] dmesg
 [ ? ] dns-clean
 [ ? ] friendly-recovery
 [ ? ] glusterfs-server
 [ - ] grub-common
 [ ? ] gssd
 [ ? ] hostname
 [ ? ] hwclock
 [ ? ] hwclock-save
 [ ? ] idmapd
 [ ? ] irqbalance
 [ ? ] killprocs
 [ ? ] module-init-tools
 [ ? ] network-interface
 [ ? ] network-interface-container
 [ ? ] network-interface-security
 [ ? ] networking
 [ ? ] ondemand
 [ ? ] passwd
 [ ? ] plymouth
 [ ? ] plymouth-log
 [ ? ] plymouth-ready
 [ ? ] plymouth-splash
 [ ? ] plymouth-stop
 [ ? ] plymouth-upstart-bridge
 [ ? ] portmap
 [ ? ] portmap-wait
 [ ? ] pppd-dns
 [ ? ] procps
 [ ? ] rc.local
 [ ? ] resolvconf
 [ ? ] rpcbind-boot
 [ - ] rsync
 [ ? ] rsyslog
 [ ? ] screen-cleanup
 [ ? ] sendsigs
 [ ? ] setvtrgb
 [ + ] ssh
 [ ? ] statd
 [ ? ] statd-mounting
 [ - ] stop-bootlogd
 [ - ] stop-bootlogd-single
 [ ? ] sudo
 [ ? ] udev
 [ ? ] udev-fallback-graphics
 [ ? ] udev-finish
 [ ? ] udevmonitor
 [ ? ] udevtrigger
 [ ? ] ufw
 [ ? ] umountfs
 [ ? ] umountnfs.sh
 [ ? ] umountroot
 [ - ] unattended-upgrades
 [ - ] urandom
 [ ? ] whoopsie

Start a service

Starting a service is done using the command service followed by the service name and the command to start the service.

service apache2 start

Stop a service

Use the stop keyword with service to stop a service.

service apache2 stop

Check the status of a service

Each service has a status, usually running or not running. Some services, such as network, may have a different output and output more information on the service.

service apache2 status

Remove a service

Use the remove keyword with update-rc.d to remove the service start up command for an application. You will need to use the -f switch if the applications /etc/init.d start up file exists.

update-rc.d -f apache2 remove

 Add a service

Adding a service to Ubuntu or Debian is done with the update-rc.d command. You can specify which runlevels to start and stop the new service or accept the defaults. The init.d file will be added to the relevent rc.d startup folders.

 update-rc.d apache2 defaults

Setting Start and Kill priority

If you need more control over when your service is asked to start and stop, you may need to set the start and kill (S and K) values.

For a given runlevel, you may have several services starting. For example, you may have apache2 and mysql both starting on runlevel 3. Ideally, you’d want mysql to start before apache2 and shutdown after apache2. In this case we need to give mysql the priority in startup, but apache2 the priority in shutdown.

When starting, the lower the number, the earlier it will start. A start priority of 10 will start before a priority of 20. When killing, it’s the opposite. A higher number will be killed before a lower number.

To set the start and kill priority we simply add them to the above update-rc.d command with the start priority first, followed by the kill priority.

update-rc.d apache2 defaults [START] [KILL]

The below command will start mysql first, then apache2. On shutdown, the kill will be the reverse of the start with apache2 being killed first and mysql second.

update-rc.d apache2 defaults 90 90
update-rc.d mysql defaults 10 10

Because, in our example, both start and kill priorities are the same we can shorted the command to just

update-rc.d apache2 defaults 90
update-rc.d mysql defaults 10

Manually set the RunLevel to Start and Kill a service

You can manually specify the Linux RunLevel that the system must be in to Start and Kill your service. See my other blog post for more information on RunLevels.

To extend the above example, we can specify exactly which RunLevel apache2 will be started and stopped.

update-rc.d apache2 start 10 2 3 4 5 . stop 90 0 1 6 .

apache2 will be started (as long as it isn’t already) when the system enters RunLevel 234 or 5 with a priority of 10. It will then be asked to stop when the system enters RunLevel 01 or 6 with a priority of 90.

Let me know in the comments if you think anything is missing.


15 Comments

Marty

14-Sep-2014 at 2:15 am

What about the services with “?” ? What does the “?” mean? Thanks.

Sparsh

21-Oct-2014 at 9:09 am

Yes what does services with “?” mean?

    james.coyle

    21-Oct-2014 at 12:04 pm

    It means it’s unknown – the service does not know the application status.

      ajolly

      19-Apr-2016 at 1:28 pm

      Mainly due to the init script not having a line to handle the explicit “status” command in the case part :-)
      (see the “/usr/sbin/service” shell script, you’ll see a grep expression for that)

      So if you have an init script that transfer the “status” command management as every other command to another script (via the “*)” in the switch case) : You’ll get a “[ ? ] myservice” printed from the “service –status-all” command.
      And this, even if that other script know the status or works great.
      In this case, you’ll get the “service myservice status” command succeed but a “[ ? ] myservice” in the “service –status-all” command.

saravana

20-Mar-2015 at 2:16 pm

best post!!! thanks….

Alexuidian

30-Apr-2015 at 1:55 pm

You forgot to mention S and K values
Start priority and kill priority…
You can set those priority by command
$update-rc.d apache2 defaults 20 21
this sets S20 and K21

Dmitry

18-May-2015 at 12:47 pm

Yep, S & K keys was forgotten.
But K means ‘add to keep list’ and S means ‘add to skip list’.

bubba

7-Oct-2015 at 5:20 am

One would think “they” would make a GUI for this ah, me wondering if this still apples to systemd and upstart systems, gots me a kubuntu 15x install here and the fstab samba mounts hang on shutdown becuse networking is stopped before network drivers are unmounted so I’m going to try:
sudo update-rc.d -f umountnfs.sh remove
sudo update-rc.d umountnfs.sh stop 15 0 6 .
maybe it will work, systemd is kinda nice I was using it on debian 8x, I don’t really care for upstart it’s not as striate forward alot of upstart stuff your like humm I dont know why it works but it works thats never good well Im off to reboot

Enterprise IT

11-Dec-2015 at 8:08 pm

Thanks for this post. Is there a way to simply start all services, or start all services that are set to automatic startup? The lack of this feature seems to be a gaping hole in Ubuntu. All instructions I’ve found are long winded listing all services and manually starting one by one. For example the version of Linux that the VMWare appliance runs on features this command:
service-control –start –all

yoochan

23-Dec-2015 at 7:29 pm

awesome esay explanation!

Jay

18-Feb-2016 at 7:17 am

Thank for this awesome post!

Is there a way to list all the services with their START & KILL priority values ?

Evee

12-Oct-2016 at 6:40 pm

Thank you so much for this :)

Alex Mason

5-Aug-2017 at 4:14 pm

This is awesome. thanks for posting.

Parthasarathy S

16-Sep-2018 at 2:58 pm

Thanks. Very useful.

tomek

28-Feb-2020 at 2:05 pm

can we start services with the same priority, example from yocto:
update-rc.d -r ${D} script1.sh start 37 S .
update-rc.d -r ${D} script2.sh start 37 S .
Only script1.sh is started or both?

Leave a Reply

Visit our advertisers

Quick Poll

Do you use ZFS on Linux?

Visit our advertisers