3

I played around with a LSB init script under Debian Wheezy(init is from sysvinit package version 2.88dsf-41+deb7u1) for learning purposes. My script is following:

# 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 /tmp/test-file

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

exit 0

#

I made the /etc/init.d/test-script file executable and added a symlink to /etc/rc2.d/ directory:

lrwxrwxrwx 1 root root 21 Nov  2 13:19 /etc/rc2.d/S04test-script -> ../init.d/test-script

..as my default runlevel is 2 and reloaded the machine, but script was not started. As a final step I also added test to /etc/init.d/.depend.start file, but /etc/init.d/test-script was still not executed during a bootup.

Which additional steps does insserv take to install an init script?

Martin
  • 7,516

2 Answers2

1

I think you have to use update-rc.d to setup the start and the stop for best results... https://www.debian-administration.org/article/28/Making_scripts_run_at_boot_time_with_Debian

From insserver's man page:

It is not recommended to execute insserv directly unless you know exactly what you're doing, doing so may render your boot system inoperable. update-rc.d is the recommended interface for managing init scripts.

GAD3R
  • 66,769
LilloX
  • 1,226
  • I am aware of this, but I would like to understand how insserv works and what does it do. – Martin Nov 02 '15 at 15:12
  • @Martin Ok, I understand. Maybe you miss to call insserv test-script ? You can check if the service is configured using chkconfig --list | grep test-script – LilloX Nov 02 '15 at 15:19
  • I would like to understand what this insserv test-script command exactly does besides calculating the dependencies between the init scripts and creating corresponding symlinks to /etc/rc<runlevel> directories based on the LSB header in init scripts. – Martin Nov 02 '15 at 16:07
  • nothing more than what you have written. In accordance with the directives it configures the system to handle the startup and the shutdown of the service, via the script. I think you have already seen this link https://wiki.debian.org/LSBInitScripts – LilloX Nov 02 '15 at 16:13
  • If the insserv doesn't do nothing more what I have written in my initial post, then why doesn't the /etc/init.d/test-script create the /tmp/test-file and /tmp/test-file-start files when the system boots into runlevel 2? – Martin Nov 02 '15 at 16:20
  • 1
    I think that insserv calculate the correct start order of script. You writed Required-Start: $all so your test-script has to be starter after all other script. Maybe the link S04test-script is not the last one... I'm assuming this. – LilloX Nov 02 '15 at 16:38
  • LilloX, good idea, but finally turned out, that I missed a simple step- I had to add test-script: line to /etc/init.d/.depend.start. – Martin Nov 03 '15 at 14:59
1

In addition to symlinks to /etc/rc<runlevel>.d/ directories, insserv adds a <script_name>: line to /etc/init.d/.depend.start file. My mistake was that I added <boot_facility>: line to /etc/init.d/.depend.start file. If we take the /etc/init.d/test-script as an example which has following LSB header:

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

..then one needs to add test-script: line to /etc/init.d/.depend.start not the test: line.

Martin
  • 7,516