123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- #!/bin/sh
- #
- # cdemu-daemon: CDEmu userspace daemon
- #
- # chkconfig: 345 98 02
- # description: This is CDEmu userspace daemon that controls CDEmu block devices \
- # and services device requests that are passed from kernel space
- #
- # processname: cdemud
- # pidfile: /var/run/cdemud.pid
- # config: /etc/sysconfig/cdemu-daemon
- #
- # so we can rearrange this easily
- processname=/usr/bin/cdemud
- servicename=cdemu-daemon
- # Sanity checks.
- if [ ! -x $processname ]; then
- echo "Daemon binary $processname not found!"
- exit 1
- fi
- # Source function library.
- . /etc/init.d/functions
- # Source config
- if [ -f /etc/sysconfig/cdemu-daemon ] ; then
- . /etc/sysconfig/cdemu-daemon
- fi
- RETVAL=0
- start() {
- # Load module
- if [ -n "$MODULE" ]; then
- echo -n $" Inserting kernel module ($MODULE): "
- /sbin/modprobe $MODULE >/dev/null 2>&1
- RETVAL=$?
- if [ $RETVAL = 0 ]; then
- success $"$base startup"
- echo
- else
- failure $"$base startup"
- echo
- return $RETVAL
- fi
- fi
-
- # Wait until control device is created...
- if [ -n "$CTL_DEVICE" ]; then
- echo -n $" Waiting for $CTL_DEVICE to be created: "
- until [ -c "$CTL_DEVICE" ]; do
- echo -n ""
- done
- fi
-
- RETVAL=0
- if [ $RETVAL -eq 0 ]; then
- success $"$base startup"
- echo
- else
- failure $"$base startup"
- echo
- return $RETVAL
- fi
-
- # Daemon arguments
- DAEMON_ARGS="--daemonize"
-
- if [ -n "$DEVICES" ]; then
- DAEMON_ARGS="$DAEMON_ARGS --num-devices=$DEVICES"
- fi
- if [ -n "$CTL_DEVICE" ]; then
- DAEMON_ARGS="$DAEMON_ARGS --ctl-device=$CTL_DEVICE"
- fi
- if [ -n "$AUDIO_BACKEND" ]; then
- DAEMON_ARGS="$DAEMON_ARGS --audio-driver=$AUDIO_BACKEND"
- fi
-
- # Start daemon
- echo -n $" Starting daemon: "
- daemon --check $servicename $processname $DAEMON_ARGS >/dev/null 2>&1
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
- success $"$base startup"
- touch /var/lock/subsys/$servicename
- echo
- else
- failure $"$base startup"
- echo
- return $RETVAL
- fi
-
- return $RETVAL
- }
- stop() {
- # Kill daemon with 'cdemud -k'
- echo -n $" Killing daemon: "
- $processname -k >/dev/null 2>&1
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
- success $"$base shutdown"
- echo
- else
- failure $"$base shutdown"
- echo
- return $RETVAL
- fi
-
- # Unload module
- if [ -n "$MODULE" ]; then
- echo -n $" Removing kernel module ($MODULE): "
- /sbin/rmmod $MODULE >/dev/null 2>&1
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
- success $"$base shutdown"
- echo
- else
- failure $"$base shutdown"
- echo
- return $RETVAL
- fi
- fi
-
- if [ $RETVAL -eq 0 ]; then
- rm -f /var/lock/subsys/$servicename
- fi
-
- return $RETVAL
- }
- # See how we were called.
- case "$1" in
- start)
- echo $"Starting CDEmu daemon: "
- start
- RETVAL=$?
- ;;
- stop)
- echo $"Stopping CDEmu daemon: "
- stop
- RETVAL=$?
- ;;
- status)
- status $processname
- RETVAL=$?
- ;;
- restart)
- echo $"Stopping CDEmu daemon: "
- stop
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
- sleep 3
- echo $"Starting CDEmu daemon: "
- start
- RETVAL=$?
- fi
- ;;
- condrestart)
- if [ -f /var/lock/subsys/$servicename ]; then
- echo $"Stopping CDEmu daemon: "
- stop
- RETVAL=$?
- if [ $RETVAL -eq 0]; then
- sleep 3
- echo $"Starting CDEmu daemon: "
- start
- fi
- fi
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|condrestart}"
- ;;
- esac
- exit $RETVAL
|