cdemu-daemon.init 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/bin/sh
  2. #
  3. # cdemu-daemon: CDEmu userspace daemon
  4. #
  5. # chkconfig: 345 98 02
  6. # description: This is CDEmu userspace daemon that controls CDEmu block devices \
  7. # and services device requests that are passed from kernel space
  8. #
  9. # processname: cdemud
  10. # pidfile: /var/run/cdemud.pid
  11. # config: /etc/sysconfig/cdemu-daemon
  12. #
  13. # so we can rearrange this easily
  14. processname=/usr/bin/cdemud
  15. servicename=cdemu-daemon
  16. # Sanity checks.
  17. if [ ! -x $processname ]; then
  18. echo "Daemon binary $processname not found!"
  19. exit 1
  20. fi
  21. # Source function library.
  22. . /etc/init.d/functions
  23. # Source config
  24. if [ -f /etc/sysconfig/cdemu-daemon ] ; then
  25. . /etc/sysconfig/cdemu-daemon
  26. fi
  27. RETVAL=0
  28. start() {
  29. # Load module
  30. if [ -n "$MODULE" ]; then
  31. echo -n $" Inserting kernel module ($MODULE): "
  32. /sbin/modprobe $MODULE >/dev/null 2>&1
  33. RETVAL=$?
  34. if [ $RETVAL = 0 ]; then
  35. success $"$base startup"
  36. echo
  37. else
  38. failure $"$base startup"
  39. echo
  40. return $RETVAL
  41. fi
  42. fi
  43. # Wait until control device is created...
  44. if [ -n "$CTL_DEVICE" ]; then
  45. echo -n $" Waiting for $CTL_DEVICE to be created: "
  46. until [ -c "$CTL_DEVICE" ]; do
  47. echo -n ""
  48. done
  49. fi
  50. RETVAL=0
  51. if [ $RETVAL -eq 0 ]; then
  52. success $"$base startup"
  53. echo
  54. else
  55. failure $"$base startup"
  56. echo
  57. return $RETVAL
  58. fi
  59. # Daemon arguments
  60. DAEMON_ARGS="--daemonize"
  61. if [ -n "$DEVICES" ]; then
  62. DAEMON_ARGS="$DAEMON_ARGS --num-devices=$DEVICES"
  63. fi
  64. if [ -n "$CTL_DEVICE" ]; then
  65. DAEMON_ARGS="$DAEMON_ARGS --ctl-device=$CTL_DEVICE"
  66. fi
  67. if [ -n "$AUDIO_BACKEND" ]; then
  68. DAEMON_ARGS="$DAEMON_ARGS --audio-driver=$AUDIO_BACKEND"
  69. fi
  70. # Start daemon
  71. echo -n $" Starting daemon: "
  72. daemon --check $servicename $processname $DAEMON_ARGS >/dev/null 2>&1
  73. RETVAL=$?
  74. if [ $RETVAL -eq 0 ]; then
  75. success $"$base startup"
  76. touch /var/lock/subsys/$servicename
  77. echo
  78. else
  79. failure $"$base startup"
  80. echo
  81. return $RETVAL
  82. fi
  83. return $RETVAL
  84. }
  85. stop() {
  86. # Kill daemon with 'cdemud -k'
  87. echo -n $" Killing daemon: "
  88. $processname -k >/dev/null 2>&1
  89. RETVAL=$?
  90. if [ $RETVAL -eq 0 ]; then
  91. success $"$base shutdown"
  92. echo
  93. else
  94. failure $"$base shutdown"
  95. echo
  96. return $RETVAL
  97. fi
  98. # Unload module
  99. if [ -n "$MODULE" ]; then
  100. echo -n $" Removing kernel module ($MODULE): "
  101. /sbin/rmmod $MODULE >/dev/null 2>&1
  102. RETVAL=$?
  103. if [ $RETVAL -eq 0 ]; then
  104. success $"$base shutdown"
  105. echo
  106. else
  107. failure $"$base shutdown"
  108. echo
  109. return $RETVAL
  110. fi
  111. fi
  112. if [ $RETVAL -eq 0 ]; then
  113. rm -f /var/lock/subsys/$servicename
  114. fi
  115. return $RETVAL
  116. }
  117. # See how we were called.
  118. case "$1" in
  119. start)
  120. echo $"Starting CDEmu daemon: "
  121. start
  122. RETVAL=$?
  123. ;;
  124. stop)
  125. echo $"Stopping CDEmu daemon: "
  126. stop
  127. RETVAL=$?
  128. ;;
  129. status)
  130. status $processname
  131. RETVAL=$?
  132. ;;
  133. restart)
  134. echo $"Stopping CDEmu daemon: "
  135. stop
  136. RETVAL=$?
  137. if [ $RETVAL -eq 0 ]; then
  138. sleep 3
  139. echo $"Starting CDEmu daemon: "
  140. start
  141. RETVAL=$?
  142. fi
  143. ;;
  144. condrestart)
  145. if [ -f /var/lock/subsys/$servicename ]; then
  146. echo $"Stopping CDEmu daemon: "
  147. stop
  148. RETVAL=$?
  149. if [ $RETVAL -eq 0]; then
  150. sleep 3
  151. echo $"Starting CDEmu daemon: "
  152. start
  153. fi
  154. fi
  155. ;;
  156. *)
  157. echo $"Usage: $0 {start|stop|status|restart|condrestart}"
  158. ;;
  159. esac
  160. exit $RETVAL