1
0

vblade.init.lsb-daemon 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: vblade
  4. # Required-Start: $remote_fs $syslog $network
  5. # Required-Stop: $remote_fs $syslog $network
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: vblade exports
  9. # Description: Manage all vlbade exports defined in
  10. # /etc/vblade.conf.d/
  11. ### END INIT INFO
  12. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  13. DESC="vblade export"
  14. NAME=vblade
  15. VBLADE="/usr/sbin/$NAME"
  16. DAEMON=/usr/bin/daemon
  17. IONICE=/usr/bin/ionice
  18. PIDDIR="/var/run/vblade/"
  19. [ -x "$VBLADE" ] || exit 0
  20. [ -x "$DAEMON" ] || exit 0
  21. mkdir -p "$PIDDIR"
  22. # Load the VERBOSE setting and other rcS variables
  23. . /lib/init/vars.sh
  24. # Define LSB functions
  25. . /lib/lsb/init-functions
  26. # Start a vblade instance
  27. #
  28. # Return
  29. # 0 if daemon has been started
  30. # 1 if daemon was already running
  31. # 2 if daemon could not be started
  32. do_start () {
  33. local INSTANCE="$1"
  34. local CONFIG="$2"
  35. sh -n "$CONFIG" 2>/dev/null || return 2
  36. shelf=
  37. slot=
  38. filename=
  39. netif=
  40. options=
  41. ionice=
  42. . "$CONFIG"
  43. [ "$netif" ] || return 2
  44. [ "$shelf" ] || return 2
  45. [ "$slot" ] || return 2
  46. [ "$filename" ] || return 2
  47. if [ "$ionice" ] ; then
  48. if [ -x "$IONICE" ] ; then
  49. ionice="$IONICE $ionice"
  50. else
  51. ionice=
  52. fi
  53. fi
  54. "$DAEMON" \
  55. --running \
  56. --name "$INSTANCE" \
  57. --pidfiles "$PIDDIR" \
  58. && return 1
  59. $ionice "$DAEMON" \
  60. --respawn \
  61. --name "$INSTANCE" \
  62. --pidfiles "$PIDDIR" \
  63. --output daemon.notice \
  64. --stdout daemon.notice \
  65. --stderr daemon.err -- \
  66. $VBLADE $options $shelf $slot $netif $filename || return 2
  67. }
  68. # Stop a vblade instance
  69. #
  70. # Return
  71. # 0 if daemon has been stopped
  72. # 1 if daemon was already stopped
  73. # 2 if daemon could not be stopped
  74. # other if a failure occurred
  75. do_stop () {
  76. local INSTANCE="$1"
  77. "$DAEMON" \
  78. --running \
  79. --name "$INSTANCE" \
  80. --pidfiles "$PIDDIR" || return 1
  81. "$DAEMON" \
  82. --stop \
  83. --name "$INSTANCE" \
  84. --pidfiles "$PIDDIR" \
  85. --stop || return 2
  86. # Wait until the process is gone
  87. for i in $(seq 1 10) ; do
  88. "$DAEMON" \
  89. --running \
  90. --name "$INSTANCE" \
  91. --pidfiles "$PIDDIR" || return 0
  92. done
  93. return 2
  94. }
  95. EXIT=0
  96. do_action () {
  97. local CONFIG="$1"
  98. INSTANCE="$(basename "${CONFIG%%.conf}")"
  99. case "$ACTION" in
  100. start)
  101. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$INSTANCE"
  102. do_start "$INSTANCE" "$CONFIG"
  103. case "$?" in
  104. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  105. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  106. esac
  107. ;;
  108. stop)
  109. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$INSTANCE"
  110. do_stop "$INSTANCE"
  111. case "$?" in
  112. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  113. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  114. esac
  115. ;;
  116. status)
  117. status_of_proc -p "$PIDDIR/$INSTANCE.pid" "$VBLADE" "vblade instance $INSTANCE" || EXIT=$?
  118. ;;
  119. restart|force-reload)
  120. log_daemon_msg "Restarting $DESC" "$INSTANCE"
  121. do_stop "$INSTANCE"
  122. case "$?" in
  123. 0|1)
  124. do_start "$INSTANCE" "$CONFIG"
  125. case "$?" in
  126. 0) log_end_msg 0 ;;
  127. *)
  128. # Old process is still running or
  129. # failed to start
  130. log_end_msg 1 ;;
  131. esac
  132. ;;
  133. *)
  134. # Failed to stop
  135. log_end_msg 1
  136. ;;
  137. esac
  138. ;;
  139. *)
  140. echo "Usage: /etc/init.d/vblade {start|stop|status|restart|force-reload} [<export> ...]" >&2
  141. exit 3
  142. ;;
  143. esac
  144. }
  145. ACTION="$1"
  146. shift
  147. if [ "$1" ] ; then
  148. while [ "$1" ] ; do
  149. CONFIG="/etc/vblade.conf.d/$1.conf"
  150. if [ -f "$CONFIG" ] ; then
  151. do_action "$CONFIG"
  152. fi
  153. shift
  154. done
  155. else
  156. for CONFIG in /etc/vblade.conf.d/*.conf ; do
  157. if [ -f "$CONFIG" ] ; then
  158. do_action "$CONFIG"
  159. fi
  160. done
  161. fi
  162. exit $EXIT