Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is a migrated question from stackoverflow, as I was told, this is the place for it to be.

I have set up a simple script to back up some directories. While I haven't had any problems setting up the functionality, I'm stuck with adding the script to rcX.d dir's using update-rc.d.

My script:

#! /bin/sh
# Provides:          backup
# Required-Start:    backup
# Required-Stop:     
# Should-Stop:       
# Default-Start:     0 6
# Default-Stop:      
# Description:       Backs up some dirs

check_mounted() {
    # Check if HD is mounted

do_backup() {
 if check_mounted; then
  # Some rsync statements.

case "$1" in
 echo "Error: argument '$1' not supported" >&2
 exit 3
 # No-op
 echo "Usage: backup [start]" >&2
 exit 3


Using update-rc.d backup start 10 0 6 . I get the following warnings and errors:

update-rc.d: warning: backup start runlevel arguments (none) do not match LSB Default-Start values (0 6)
update-rc.d: warning: backup stop runlevel arguments (0 6.) do not match LSB Default-Stop values (none)
update-rc.d: error: start|stop arguments not terminated by "."

The syntax I try to use is the following:

update-rc.d [-n] <basename> start|stop NN runlvl [runlvl] [...] .

Google wasn't that helpful at finding a solution. How can I correctly set up a script and add it via update-rc.d?

I'm using Ubuntu 9.10.


Using update-rc.d backup start 10 0 6 . stop 10 0 . the error disappears. The warnings about default values persists:

update-rc.d: warning: backup start runlevel arguments (none) do not match LSB Default-Start values (0 6)
update-rc.d: warning: backup stop runlevel arguments (0 6 0 6) do not match LSB Default-Stop values (none)

It even is added to the appropiate rcX-dirs but it still does not get executed...

share|improve this question
up vote 2 down vote accepted

It doesn't make sense to start a service in run level 0 or 6, which are the levels for shutdown and reboot, respectively. There is apparently some magic in update-rc.d that attempts to prevent this case and misparses the arguments in that case. If you use more sensible run levels for start (probably 2 3 4 5), it will work better.

share|improve this answer
Thanks for your answer, but as I want the script to run on entering shutdown (0) and reboot (6) I don't have much of a choice, or do I? – user34881 Feb 17 '10 at 11:56
Then you probably ought to put your do_backup invocation into the "stop" section of the init script instead. I'm not sure, however, whether it's such a good idea to set things up that way. Delaying shutdown or reboot by overloading it with other actions may come back to bite you. Also, you will need to do more fine-tuning of the dependencies of your init script so that, for example, it doesn't run after the network is already shut down. It might not actually work in all cases. – Peter Eisentraut Feb 17 '10 at 22:34
Great! It works! Using stop instead of start and therefor declaring it as a killing script did the trick! I used a very low priority number, so it gets executed first and before any umounting is done.It's a local backup, only for me, so I can skip the requierements. Thanks again! – user34881 Feb 18 '10 at 14:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.