How to conform to update-rc.d with LSB standard?
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.
Related videos on Youtube
Community
Updated on September 17, 2022Comments
-
Community almost 2 years
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...
-
Admin over 14 yearsThanks 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?
-
Peter Eisentraut over 14 yearsThen 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. -
Admin over 14 yearsGreat! 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!