#!/bin/sh
#
# cpcieject	Bring the shutdown daemon up/down
#

DAEMON=/usr/sbin/cpcieject

case "$1" in
  start)
	echo -n "Starting cpcieject daemon: "
	modprobe cpcieject
	MAJOR=`cat /proc/devices | grep cpcieject | cut -d' ' -f1`

	if [ "$MAJOR" == "" ]; then
	    echo "device not found, exiting"
	    exit 0
	fi

	if [ -c "/dev/cpcieject" ]
	then
		rm -f /dev/cpcieject
	fi

	mknod /dev/cpcieject c $MAJOR 0

	$DAEMON
	RETVAL=$?

	echo
	;;
  stop)
	echo -n "Stopping cpcieject daemon: "

	PID=`ps ax | grep $DAEMON | grep -v "grep" | cut -c1-6`

	if [ "$PID" == "" ]; then
	    exit 0
	fi

	kill -s 1 $PID

	echo
	RETVAL=0
	;;
  force-reload)	
	$0 stop
	$0 start
	RETVAL=$?
	;;
  restart)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  *)
	echo "Usage: cpcieject {start|stop|restart|force-reload}"
	exit 1
esac

exit $RETVAL
