1#! /bin/sh
2
3# Author: iSteve <isteve@bofh.cz>
4#
5# Note that this script is untested!
6
7# PATH should only include /usr/* if it runs after the mountnfs.sh script
8PATH=/sbin:/bin
9DESC="Hotplug2"
10NAME=hotplug2
11DAEMON=/sbin/$NAME
12DAEMON_ARGS="--coldplug --persistent"
13PIDFILE=/var/run/$NAME.pid
14SCRIPTNAME=/etc/init.d/$NAME
15
16# Load the VERBOSE setting and other rcS variables
17[ -f /etc/default/rcS ] && . /etc/default/rcS
18
19# Define LSB log_* functions.
20# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
21. /lib/lsb/init-functions
22
23#
24# Function that starts the daemon/service
25#
26do_start()
27{
28	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
29		|| return 1
30	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
31		$DAEMON_ARGS \
32		|| return 2
33}
34
35#
36# Function that stops the daemon/service
37#
38do_stop()
39{
40	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
41	RETVAL="$?"
42	[ "$RETVAL" = 2 ] && return 2
43
44	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
45	[ "$?" = 2 ] && return 2
46	# Many daemons don't delete their pidfiles when they exit.
47	rm -f $PIDFILE
48	return "$RETVAL"
49}
50
51case "$1" in
52  start)
53  	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
54	
55	case "$(uname -r)" in 
56	    2.[0123].*)
57		    log_end_msg 0
58		    exit 1;
59		    ;;
60	    2.[45].*)
61		    echo "/sbin/hotplug2-dnode" > /proc/sys/kernel/hotplug
62		    DAEMON_ARGS=${DAEMON_ARGS}" --set-coldplug-cmd /sbin/hotplug2-coldplug-2.4"
63		    ;;
64	    *)
65		    # 2.6 needs no extra flags
66		    ;;
67	esac
68	
69	do_start
70	case "$?" in
71		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
72		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
73	esac
74	;;
75  stop)
76	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
77	do_stop
78	case "$?" in
79		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
80		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
81	esac
82	;;
83  *)
84	echo "Usage: $SCRIPTNAME {start|stop}" >&2
85	exit 3
86	;;
87esac
88