2

What causes insserv: warning: script 'XXX.sh' missing LSB tags and overrides, and how is it prevented?

pi@raspberrypi /etc/init.d $ sudo rm 5_*
pi@raspberrypi /etc/init.d $ sudo vi /etc/init.d/5_second_cron
pi@raspberrypi /etc/init.d $ sudo chmod +x /etc/init.d/5_second_cron
pi@raspberrypi /etc/init.d $ sudo update-rc.d /etc/init.d/5_second_cron defaults^C
pi@raspberrypi /etc/init.d $

5_second_cron.sh is the following:

#!/bin/bash
while true
do
 /usr/bin/php /var/www/cron.php
 sleep 5
done

EDIT. Tried the following. Script just "hung" when I executed $ sudo update-rc.d /etc/init.d/5_second_cron.

pi@raspberrypi /etc/init.d $ sudo vi /etc/init.d/5_second_cron
pi@raspberrypi /etc/init.d $ sudo chmod +x /etc/init.d/5_second_cron
pi@raspberrypi /etc/init.d $ sudo update-rc.d /etc/init.d/5_second_cron defaults^.C
pi@raspberrypi /etc/init.d $

5_second_cron is the following:

#!/bin/bash
# /etc/init.d/5_second_cron

### BEGIN INIT INFO
# Provides:          5_second_cron
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: PHP Loop
# Description:       Initiate a given PHP file every 5 seconds
### END INIT INFO

while true
do
 /usr/bin/php /var/www/cron.php
 sleep 5
done
exit 0

EDIT2. Messing around some more, and now this:

pi@raspberrypi /etc/init.d $ sudo update-rc.d /etc/init.d/5_second_cron defaults
update-rc.d: using dependency based boot sequencing
update-rc.d: error: unable to read /etc/init.d//etc/init.d/5_second_cron
4
  • I don't see any LSB tags, you should add them. Also, an init script that doesn't return (like this one) will block booting with sysvinit.
    – jordanm
    Oct 10, 2015 at 17:33
  • @jordanm LSB tags meaning en.wikipedia.org/wiki/Linux_Standard_Base? Should I just add something like return 1? Oct 10, 2015 at 17:36
  • 1
    See: wiki.debian.org/LSBInitScripts. What you need to do is put your script in a separate file and write a proper init script to put in /etc/init.d that launches the script in the post.
    – jordanm
    Oct 10, 2015 at 17:38
  • @jordanm I hopefully did what you advised. Please see the new part of my original question under "EDIT". Thanks Oct 10, 2015 at 19:32

1 Answer 1

1

Sorry about the very late answer.

Init scripts aren't meant to run persistently. What I mean by this is that the init scripts are supposed to start the program, then exit, leaving the program running in the background. This way, the init system knows the runlevel has been reached.

Therefore, I would recommend putting your script into a separate folder, say /usr/bin. This is what it would contain:

#!/bin/sh

while true
do
 /usr/bin/php /var/www/cron.php
 sleep 5
done

In your init script, put the following:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          5_second_cron
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: PHP Loop
# Description:       Initiate a given PHP file every 5 seconds
### END INIT INFO

case "$1" in
start)
    setsid /path/to/your/script.sh >/dev/null 2>&1 < /dev/null &
    ;;
*)
    ;;
esac

This makes it so the script takes the start argument, which is the way it is invoked, and also detaches the actual script from the process as a background daemon.

After these edits, simply run:

$ sudo insserv 5_second_cron

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.