aoetools.init 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #! /bin/sh
  2. #
  3. # Based on a example file to build /etc/init.d/ scripts,
  4. # written by Miquel van Smoorenburg <miquels@cistron.nl>
  5. # and later modified by Ian Murdock <imurdock@gnu.ai.mit.edu>.
  6. #
  7. # Also based on init script mountnfs.sh from initscripts package.
  8. #
  9. # Modified for aoetools by David Martínez Moreno <ender@debian.org>.
  10. # Copyright 2006-2014. Under GPLv2.
  11. #
  12. # Support for LVM and other mount points contributed by Glen W. Mabey.
  13. # Support for RAID contributed by Gabor Kiss.
  14. #
  15. ### BEGIN INIT INFO
  16. # Provides: aoe aoetools
  17. # Required-Start: $local_fs $network
  18. # Required-Stop: $local_fs $network
  19. # Should-Start:
  20. # Default-Start: S
  21. # Default-Stop: 0 6
  22. # Short-Description: Begin AoE discovery and mount related filesystems.
  23. # Description: Begin AoE discovery and mount filesystems residing
  24. # on AoE volumes.
  25. ### END INIT INFO
  26. NAME=aoetools
  27. DESC="AoE devices discovery and mounting AoE filesystems"
  28. [ -f /etc/default/rcS ] && . /etc/default/rcS
  29. . /lib/lsb/init-functions
  30. # Include aoetools defaults if available
  31. if [ -f /etc/default/aoetools ]
  32. then
  33. . /etc/default/aoetools
  34. fi
  35. set -e
  36. create_fs_list() {
  37. # We start with a list from /etc/default/aoetools.
  38. waitaoe="$AOEMOUNTS"
  39. [ -f /etc/fstab ] || return
  40. #
  41. # Read through fstab line by line. If it contains /dev/etherd, set the flag
  42. # for mounting file systems over AoE.
  43. #
  44. exec 9<&0 </etc/fstab
  45. while read DEV MTPT FSTYPE OPTS REST
  46. do
  47. case "$OPTS" in
  48. noauto|*,noauto|noauto,*|*,noauto,*)
  49. continue
  50. ;;
  51. esac
  52. case "$DEV" in
  53. ''|\#*)
  54. continue
  55. ;;
  56. /dev/etherd/*)
  57. waitaoe="$waitaoe $MTPT"
  58. esac
  59. done
  60. exec 0<&9 9<&-
  61. }
  62. do_start() {
  63. # We exit if the user does not want us to try this.
  64. if [ "$INTERFACES" = "none" ]
  65. then
  66. log_action_msg "INTERFACES='none' in /etc/default/aoetools, not started."
  67. exit 0
  68. fi
  69. # Usually aoe is a module, so we will try to load it.
  70. if [ -n "$INTERFACES" ]
  71. then
  72. modprobe aoe aoe_iflist="$INTERFACES" >/dev/null 2>&1 || true
  73. else
  74. modprobe aoe >/dev/null 2>&1 || true
  75. fi
  76. # Also, if udev is being used, the /dev/etherd devices
  77. # are not created until aoe module insertion, so...
  78. sleep 1 # ...we give udev a chance to populate /dev/etherd/.
  79. if [ ! -c /dev/etherd/discover ]
  80. then
  81. log_failure_msg "Missing devices under /dev/etherd/. Please run aoe-mkdevs /dev/etherd and try again." >&2
  82. exit 1
  83. fi
  84. # Try to set up interfaces for discovery, if any.
  85. if [ -n "$INTERFACES" ]
  86. then
  87. aoe-interfaces $INTERFACES
  88. fi
  89. aoe-discover
  90. create_fs_list
  91. if [ -n "$waitaoe" ]
  92. then
  93. echo
  94. fi
  95. if [ ! -x '/sbin/mdadm' -a -n "$RAID_ARRAYS" ]
  96. then
  97. echo
  98. echo "/sbin/mdadm is not present. Please install mdadm package and try again." >&2
  99. echo "RAID_ARRAYS option is ignored." >&2
  100. RAID_ARRAYS=''
  101. fi
  102. if [ -n "$RAID_ARRAYS" ]
  103. then
  104. echo "Assembling RAID arrays..."
  105. for md in $RAID_ARRAYS
  106. do
  107. /sbin/mdadm --assemble $md --scan
  108. done
  109. fi
  110. if [ ! -x '/sbin/vgchange' -a -n "$LVMGROUPS" ]
  111. then
  112. echo
  113. echo "The LVM2 tools are not present. Please install lvm2 package and try again." >&2
  114. echo "We will not honour LVMGROUPS." >&2
  115. LVMGROUPS=''
  116. fi
  117. if [ -n "$LVMGROUPS" ]
  118. then
  119. echo "Assembling LVM2 groups..."
  120. for vg in "$LVMGROUPS"
  121. do
  122. vgchange --available=y $vg
  123. done
  124. fi
  125. if [ -n "$waitaoe" ]
  126. then
  127. for mountpt in $waitaoe
  128. do
  129. echo "Mounting $mountpt..."
  130. mount $mountpt
  131. #log_action_begin_msg "Waiting for $mountpt."
  132. done
  133. else
  134. echo "Nothing to mount."
  135. fi
  136. }
  137. do_stop() {
  138. create_fs_list
  139. if [ -n "$waitaoe" ]
  140. then
  141. for mountpt in $waitaoe; do
  142. if [ -z "`awk '{print $2}' < /proc/mounts | grep -w $mountpt$`" ]
  143. then
  144. # It's already been unmounted.
  145. continue
  146. fi
  147. echo "Unmounting $mountpt..."
  148. umount $mountpt
  149. done
  150. fi
  151. if [ -n "$LVMGROUPS" ]
  152. then
  153. for vg in "$LVMGROUPS"
  154. do
  155. vgchange --available=n $vg
  156. done
  157. fi
  158. if [ -x /sbin/mdadm -a -n "$RAID_ARRAYS" ]
  159. then
  160. echo "Stopping RAID arrays..."
  161. for md in $RAID_ARRAYS
  162. do
  163. /sbin/mdadm --stop /dev/$md
  164. done
  165. fi
  166. # Removing the module prevents LVM's "Shutting down LVM Volume Groups..."
  167. # from hanging when an LVM has been setup on a device in /dev/etherd/.
  168. modprobe --remove aoe >/dev/null 2>&1 || true
  169. }
  170. do_status() {
  171. if $(lsmod |grep -qw '^aoe\s')
  172. then
  173. echo 'The aoe module is loaded.'
  174. fi
  175. # FIXME: Make something smarter like detect udev or a monolithic kernel.
  176. AOE_MOUNTS="$(grep '/dev/etherd/' /proc/mounts || true)"
  177. if [ -n "$AOE_MOUNTS" ]
  178. then
  179. echo 'The following AoE file systems are mounted:'
  180. echo "$AOE_MOUNTS" | awk '{print $2}'
  181. else
  182. echo 'No AoE file systems mounted.'
  183. fi
  184. }
  185. case "$1" in
  186. start|restart|reload|force-reload)
  187. echo -n "Starting $DESC: "
  188. do_start
  189. ;;
  190. stop)
  191. echo "Stopping $DESC: "
  192. do_stop
  193. ;;
  194. status)
  195. do_status
  196. ;;
  197. *)
  198. N=/etc/init.d/$NAME
  199. echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
  200. exit 1
  201. ;;
  202. esac
  203. exit 0