#!/bin/sh
#
# chkconfig:	2345 01 99
# description:	Starts and stops each hotpluggable subsystem.
#		On startup, may simulate hotplug events for devices
#		that were present at boot time, before filesystems
#		used by /sbin/hotplug became available.
#
# $Id: hotplug.init,v 1.3 2002/01/17 12:39:01 ukai Exp $
#
PATH=/sbin:/bin
test -x /sbin/hotplug || exit 0

case "$1" in
start)
    echo -n "Starting hotplug subsystem:"
    if [ "$runlevel" = "S" ]; then
	: > /etc/nohotplug
    elif grep -q "^/sbin/hotplug$" /proc/sys/kernel/hotplug; then
	# but, pending hotplug action will be executed
	rm -f $(readlink -f /etc/nohotplug)
	echo ".... already started. process pending events."
	exit 0
    fi
    echo /sbin/hotplug > /proc/sys/kernel/hotplug
    if [ "$runlevel" != "S" ]; then
	rm -f $(readlink -f /etc/nohotplug)
	# XXX: need wait?
    fi
    for RC in /etc/hotplug/*.rc
    do
        basename=${RC#/etc/hotplug/}
        name=${basename%.rc}
	echo -n " $name"
	$RC $1
    done
    echo "."
    ;;
stop)
    echo -n "Stopping hotplug subsystem:"
    case R"$runlevel" in
    R0|R6)
	;;
    *)
     for RC in /etc/hotplug/*.rc
     do
        basename=${RC#/etc/hotplug/}
        name=${basename%.rc}
	echo -n " $name"
       $RC stop
     done
     ;;
    esac
    echo /bin/true > /proc/sys/kernel/hotplug
    echo "."
    ;;
restart|force-reload)
    echo -n "Restarting hotplug subsystem:"
    $0 stop
    $0 start
    ;;
status)
    for RC in /etc/hotplug/*.rc
    do
	$RC $1
    done
    ;;
*)
    echo "Usage: $0 {start|stop|restart|status|force-reload}" >&2
    exit 1
    ;;
esac
exit 0
