Install init scripts manually under Debian Wheezy

init-scriptsysvinit

I played around with LSB-compatible init-scripts under Debian Wheezy (init is from sysvinit package version 2.88dsf-41+deb7u1). My script in the /etc/init.d directory is as follows:

root@T60:~# ls -l /etc/init.d/test-script
-rwxr-xr-x 1 root root 811 Aug 10 03:18 /etc/init.d/test-script
root@T60:~# cat /etc/init.d/test-script
#! /bin/sh

### BEGIN INIT INFO
# Provides:          test
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: test script
# Description:       test script
### END INIT INFO

# always executes
touch /var/test-file

case "$1" in
  start)
    echo "Starting script test"
    touch /var/test-file-start
    ;;
  stop)
    echo "Stopping script test"
    touch /var/test-file-stop
    ;;
  restart)
    echo "Restarting script test"
    touch /var/test-file-restart
    ;;
  force-reload)
    echo "Force-reloading script test"
    touch /var/test-file-force-reload
    ;;
  status)
    echo "Status of test"
    touch /var/test-file-status
    ;;
  *)
    echo "Usage: /etc/init.d/test-script {start|stop}"
    exit 1
    ;;
esac

exit 0
root@T60:~# 

As a next step I added symlink to /etc/rc3.d directory:

root@T60:~# file /etc/rc3.d/S05test-script
/etc/rc3.d/S05test-script: symbolic link to `../init.d/test-script'
root@T60:~# 

Now if I changed my runlevel from 2 to 3 I expected script to be executed, but this did not happen:

root@T60:~# who -r
         run-level 2  2014-08-01 20:47                   last=S
root@T60:~# init 3
root@T60:~# who -r
         run-level 3  2014-08-10 03:27                   last=2
root@T60:~# ls -l /var/test*
ls: cannot access /var/test*: No such file or directory
root@T60:~# 

I am aware that I could use insserv or update-rc.d to install scripts and then they will work as expected. Am I correct that both insserv and update-rc.d take some additional steps when enabling the script besides installing the symlinks? If yes, then which steps?

Best Answer

You can automatically create the /etc/rcX symlinks using the update-rc.d command. Here is some more information about update-rc.d.

In your particular example, this should do it:

update-rc.d test-script defaults

To remove it later, use:

update-rc.d -f test-script remove