aoetools.init 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. echo "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. echo
  82. echo "Missing devices under /dev/etherd/. Please run" >&2
  83. echo " aoe-mkdevs /dev/etherd" >&2
  84. echo "and try again." >&2
  85. exit 1
  86. fi
  87. # Try to set up interfaces for discovery, if any.
  88. if [ -n "$INTERFACES" ]
  89. then
  90. aoe-interfaces $INTERFACES
  91. fi
  92. aoe-discover
  93. create_fs_list
  94. if [ -n "$waitaoe" ]
  95. then
  96. echo
  97. fi
  98. if [ ! -x '/sbin/mdadm' -a -n "$RAID_ARRAYS" ]
  99. then
  100. echo
  101. echo "/sbin/mdadm is not present. Please install mdadm package and try again." >&2
  102. echo "RAID_ARRAYS option is ignored." >&2
  103. RAID_ARRAYS=''
  104. fi
  105. if [ -n "$RAID_ARRAYS" ]
  106. then
  107. echo "Assembling RAID arrays..."
  108. for md in $RAID_ARRAYS
  109. do
  110. /sbin/mdadm --assemble $md --scan
  111. done
  112. fi
  113. if [ ! -x '/sbin/vgchange' -a -n "$LVMGROUPS" ]
  114. then
  115. echo
  116. echo "The LVM2 tools are not present. Please install lvm2 package and try again." >&2
  117. echo "We will not honour LVMGROUPS." >&2
  118. LVMGROUPS=''
  119. fi
  120. if [ -n "$LVMGROUPS" ]
  121. then
  122. echo "Assembling LVM2 groups..."
  123. for vg in "$LVMGROUPS"
  124. do
  125. vgchange --available=y $vg
  126. done
  127. fi
  128. if [ -n "$waitaoe" ]
  129. then
  130. for mountpt in $waitaoe
  131. do
  132. echo "Mounting $mountpt..."
  133. mount $mountpt
  134. #log_action_begin_msg "Waiting for $mountpt."
  135. done
  136. else
  137. echo "Nothing to mount."
  138. fi
  139. }
  140. do_stop() {
  141. create_fs_list
  142. if [ -n "$waitaoe" ]
  143. then
  144. for mountpt in $waitaoe; do
  145. if [ -z "`awk '{print $2}' < /proc/mounts | grep -w $mountpt$`" ]
  146. then
  147. # It's already been unmounted.
  148. continue
  149. fi
  150. echo "Unmounting $mountpt..."
  151. umount $mountpt
  152. done
  153. fi
  154. if [ -n "$LVMGROUPS" ]
  155. then
  156. for vg in "$LVMGROUPS"
  157. do
  158. vgchange --available=n $vg
  159. done
  160. fi
  161. if [ -x /sbin/mdadm -a -n "$RAID_ARRAYS" ]
  162. then
  163. echo "Stopping RAID arrays..."
  164. for md in $RAID_ARRAYS
  165. do
  166. /sbin/mdadm --stop /dev/$md
  167. done
  168. fi
  169. # Removing the module prevents LVM's "Shutting down LVM Volume Groups..."
  170. # from hanging when an LVM has been setup on a device in /dev/etherd/.
  171. modprobe --remove aoe >/dev/null 2>&1 || true
  172. }
  173. do_status() {
  174. if $(lsmod |grep -qw '^aoe\s')
  175. then
  176. echo 'The aoe module is loaded.'
  177. fi
  178. # FIXME: Make something smarter like detect udev or a monolithic kernel.
  179. AOE_MOUNTS="$(grep '/dev/etherd/' /proc/mounts || true)"
  180. if [ -n "$AOE_MOUNTS" ]
  181. then
  182. echo 'The following AoE file systems are mounted:'
  183. echo "$AOE_MOUNTS" | awk '{print $2}'
  184. else
  185. echo 'No AoE file systems mounted.'
  186. fi
  187. }
  188. case "$1" in
  189. start|restart|reload|force-reload)
  190. echo -n "Starting $DESC: "
  191. do_start
  192. ;;
  193. stop)
  194. echo "Stopping $DESC: "
  195. do_stop
  196. ;;
  197. status)
  198. do_status
  199. ;;
  200. *)
  201. N=/etc/init.d/$NAME
  202. echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
  203. exit 1
  204. ;;
  205. esac
  206. exit 0