aoetools.init 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. # shellcheck source=/dev/null
  29. [ -f /etc/default/rcS ] && . /etc/default/rcS
  30. . /lib/lsb/init-functions
  31. # Include aoetools defaults if available
  32. [ -f /etc/default/aoetools ] && . /etc/default/aoetools
  33. set -e
  34. mdadm="$(command -v mdadm || :)"
  35. vgchange="$(command -v vgchange || :)"
  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. # shellcheck disable=SC2034 # fstype is indeed not used
  46. while read -r device mountpoint fstype fsopts rest; do
  47. case "$fsopts" in
  48. noauto | *,noauto | noauto,* | *,noauto,*)
  49. continue
  50. ;;
  51. esac
  52. case "$device" in
  53. '' | \#*)
  54. continue
  55. ;;
  56. /dev/etherd/*)
  57. waitaoe="$waitaoe $mountpoint"
  58. ;;
  59. esac
  60. done
  61. exec 0<&9 9<&-
  62. }
  63. do_start() {
  64. # We exit if the user does not want us to try this.
  65. if [ "$INTERFACES" = "none" ]; 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" ]; then
  71. modprobe aoe aoe_iflist="$INTERFACES" >/dev/null 2>&1 || true
  72. else
  73. modprobe aoe >/dev/null 2>&1 || true
  74. fi
  75. # Also, if udev is being used, the /dev/etherd devices
  76. # are not created until aoe module insertion, so...
  77. sleep 1 # ...we give udev a chance to populate /dev/etherd/.
  78. if [ ! -c /dev/etherd/discover ]; then
  79. log_failure_msg "Missing devices under /dev/etherd/. Please run aoe-mkdevs /dev/etherd and try again." >&2
  80. exit 1
  81. fi
  82. # Try to set up interfaces for discovery, if any.
  83. if [ -n "$INTERFACES" ]; then
  84. # shellcheck disable=SC2086 # See warning in /etc/default/aoetools
  85. aoe-interfaces $INTERFACES
  86. fi
  87. aoe-discover
  88. create_fs_list
  89. if [ -n "$waitaoe" ]; then
  90. echo
  91. fi
  92. if [ "$mdadm" ] && [ -n "$RAID_ARRAYS" ]; then
  93. echo
  94. echo "/sbin/mdadm is not present. Please install mdadm package and try again." >&2
  95. echo "RAID_ARRAYS option is ignored." >&2
  96. RAID_ARRAYS=''
  97. fi
  98. if [ -n "$RAID_ARRAYS" ]; then
  99. echo "Assembling RAID arrays..."
  100. for md in $RAID_ARRAYS; do
  101. /sbin/mdadm --assemble "$md" --scan
  102. done
  103. fi
  104. if [ "$vgchange" ] && [ -n "$LVMGROUPS" ]; then
  105. echo
  106. echo "The LVM2 tools are not present. Please install lvm2 package and try again." >&2
  107. echo "We will not honour LVMGROUPS." >&2
  108. LVMGROUPS=''
  109. fi
  110. if [ -n "$LVMGROUPS" ]; then
  111. echo "Assembling LVM2 groups..."
  112. for vg in $LVMGROUPS; do
  113. vgchange --available=y "$vg"
  114. done
  115. fi
  116. if [ -n "$waitaoe" ]; then
  117. for mountpt in $waitaoe; do
  118. echo "Mounting $mountpt..."
  119. mount "$mountpt"
  120. #log_action_begin_msg "Waiting for $mountpt."
  121. done
  122. else
  123. echo "Nothing to mount."
  124. fi
  125. }
  126. do_stop() {
  127. create_fs_list
  128. if [ -n "$waitaoe" ]; then
  129. for mountpt in $waitaoe; do
  130. if awk '{print $2}' </proc/mounts | grep -qFx "$mountpt"; then
  131. echo "Unmounting $mountpt..."
  132. umount "$mountpt"
  133. fi
  134. done
  135. fi
  136. if [ -n "$LVMGROUPS" ]; then
  137. for vg in $LVMGROUPS; do
  138. vgchange --available=n "$vg"
  139. done
  140. fi
  141. if [ "$mdadm" ] && [ -n "$RAID_ARRAYS" ]; then
  142. echo "Stopping RAID arrays..."
  143. for md in $RAID_ARRAYS; do
  144. /sbin/mdadm --stop "/dev/$md"
  145. done
  146. fi
  147. # Removing the module prevents LVM's "Shutting down LVM Volume Groups..."
  148. # from hanging when an LVM has been setup on a device in /dev/etherd/.
  149. modprobe --remove aoe >/dev/null 2>&1 || true
  150. }
  151. do_status() {
  152. local aoe_mounts
  153. if lsmod | grep -qFx 'aoe'; then
  154. echo 'The aoe module is loaded.'
  155. fi
  156. # FIXME: Make something smarter like detect udev or a monolithic kernel.
  157. aoe_mounts="$(grep '/dev/etherd/' /proc/mounts || true)"
  158. if [ -n "$aoe_mounts" ]; then
  159. echo 'The following AoE file systems are mounted:'
  160. echo "$aoe_mounts" | awk '{print $2}'
  161. else
  162. echo 'No AoE file systems mounted.'
  163. fi
  164. }
  165. case "$1" in
  166. start | restart | reload | force-reload)
  167. printf '%s' "Starting $DESC: "
  168. do_start
  169. ;;
  170. stop)
  171. echo "Stopping $DESC: "
  172. do_stop
  173. ;;
  174. status)
  175. do_status
  176. ;;
  177. *)
  178. N=/etc/init.d/$NAME
  179. echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
  180. exit 1
  181. ;;
  182. esac
  183. exit 0