[Pkg-sysvinit-devel] Make init.d/skeleton a very simple init.d script?

Petter Reinholdtsen pere at hungry.com
Mon Feb 3 21:58:00 UTC 2014


Thank you for the feedback and ideas, here and on IRC.  I adjusted the
draft a bit, and now believe the prototype is working.  As a test, I
picked a init.d script (the alphabetically first) on my machine, and
implemented it using the init-d-script system.  The behavior changed
slightly:

  root at minerva:~# /etc/init.d/acpi-fakekey restart
  [ ok ] Restarting acpi_fakekey daemon...done.
  root at minerva:~# ./acpi-fakekey-new restart
  [ ok ] Stopping acpi_fakekey daemon: acpi_fakekeyd.
  [ ok ] Preparing to start acpi_fakekey daemon...done.
  [ ok ] Starting acpi_fakekey daemon: acpi_fakekeyd.
  root at minerva:~# 

Would such change be acceptable?  Here is the script in question
reduced from 69 to 40 lines:

#!/lib/init/init-d-script
### BEGIN INIT INFO
# Provides:          acpi-fakekey
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      
# Short-Description: Start acpi_fakekey daemon
### END INIT INFO
DESC="acpi_fakekey daemon"
DAEMON=/usr/sbin/acpi_fakekeyd
do_start_prepare() {
    log_action_begin_msg "Preparing to start acpi_fakekey daemon"
    if [ ! -d /sys/devices/virtual/misc/uinput ]; then
        if ! modprobe -q uinput; then
            if ! find /lib/modules/`uname -r` -name "uinput\.*" 2>/dev/null|grep -q uinput; then
                log_action_end_msg 1 "No suitable uinput module for running kernel found"
            else
                log_action_end_msg 1 "Modprobe uinput failed. Please use 'dmesg' to find out why"
            fi
        fi
        # give udev time to create the devices
        sleep 1
    else
        log_action_end_msg 0
    fi
}

do_start_cmd_override() {
    if [ -d /sys/devices/virtual/misc/uinput ]; then
	start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/acpi_fakekeyd
    else
	return 0
    fi
}

do_stop_cmd_override() {
    start-stop-daemon --stop --quiet --exec /usr/sbin/acpi_fakekeyd
}
:

I guess the changed behaviour could be slightly changed by rewriting
do_restart to use do_stop_cmd and do_start_cmd instead of do_stop and
do_start, but am not sure it is a good idea.

I also tried the same with an even simpler script, /etc/init.d/atd,
which become this 16 lines script:

#!/lib/init/init-d-script
### BEGIN INIT INFO
# Provides:          atd
# Required-Start:    $syslog $time $remote_fs
# Required-Stop:     $syslog $time $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Deferred execution scheduler
# Description:       Debian init script for the atd deferred executions
#                    scheduler
### END INIT INFO
#
# Author:	Ryan Murray <rmurray at debian.org>
#
DESC="deferred execution scheduler"
DAEMON=/usr/sbin/atd

Please try with other init.d scripts and see if the current API and
available hooks make sense.

-- 
Happy hacking
Petter Reinholdtsen



More information about the Pkg-sysvinit-devel mailing list