4

This is a migrated question from stackoverflow, as I was told, this is the place for it to be. https://stackoverflow.com/questions/2263567/how-to-conform-to-update-rc-d-with-lsb-standard

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
### BEGIN INIT INFO
# Provides:          backup
# Required-Start:    backup
# Required-Stop:     
# Should-Stop:       
# Default-Start:     0 6
# Default-Stop:      
# Description:       Backs up some dirs
### END INIT INFO

check_mounted() {
    # Check if HD is mounted
}

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

case "$1" in
  start)
 do_backup
 ;;
  restart|reload|force-reload)
 echo "Error: argument '$1' not supported" >&2
 exit 3
 ;;
  stop|"")
 # No-op
 ;;
  *)
 echo "Usage: backup [start]" >&2
 exit 3
 ;;
esac

:

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.

UPDATE

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...

1 Answers1

2

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.

Peter Eisentraut
  • 3,575
  • 1
  • 23
  • 21
  • 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? –  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! –  Feb 18 '10 at 14:11