aoetools.init 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. #
  14. ### BEGIN INIT INFO
  15. # Provides: aoe aoetools
  16. # Required-Start: $local_fs $network
  17. # Required-Stop: $local_fs $network
  18. # Should-Start:
  19. # Default-Start: S
  20. # Default-Stop: 0 6
  21. # Short-Description: Begin AoE discovery and mount related filesystems.
  22. # Description: Begin AoE discovery and mount filesystems residing
  23. # on AoE volumes.
  24. ### END INIT INFO
  25. NAME=aoetools
  26. DESC="AoE devices discovery and mounting AoE filesystems"
  27. [ -f /etc/default/rcS ] && . /etc/default/rcS
  28. . /lib/lsb/init-functions
  29. # Include aoetools defaults if available
  30. if [ -f /etc/default/aoetools ] ; then
  31. . /etc/default/aoetools
  32. fi
  33. set -e
  34. create_fs_list() {
  35. # We start with a list from /etc/default/aoetools.
  36. waitaoe="$AOEMOUNTS"
  37. [ -f /etc/fstab ] || return
  38. #
  39. # Read through fstab line by line. If it contains /dev/etherd, set the flag
  40. # for mounting file systems over AoE.
  41. #
  42. exec 9<&0 </etc/fstab
  43. while read DEV MTPT FSTYPE OPTS REST
  44. do
  45. case "$OPTS" in
  46. noauto|*,noauto|noauto,*|*,noauto,*)
  47. continue
  48. ;;
  49. esac
  50. case "$DEV" in
  51. ""|\#*)
  52. continue
  53. ;;
  54. /dev/etherd/*)
  55. waitaoe="$waitaoe $MTPT"
  56. esac
  57. done
  58. exec 0<&9 9<&-
  59. }
  60. do_start() {
  61. # We exit if the user does not want us to try this.
  62. if [ "$INTERFACES" = "none" ]
  63. then
  64. echo "not started."
  65. exit 0
  66. fi
  67. # Usually aoe is a module, so we will try to load it.
  68. if [ -n "$INTERFACES" ]
  69. then
  70. modprobe aoe aoe_iflist="$INTERFACES" >/dev/null 2>&1 || true
  71. else
  72. modprobe aoe >/dev/null 2>&1 || true
  73. fi
  74. # Also, if udev is being used, the /dev/etherd devices
  75. # are not created until aoe module insertion, so...
  76. sleep 1 # ...we give udev a chance to populate /dev/etherd/.
  77. if [ ! -c /dev/etherd/discover ]
  78. then
  79. echo
  80. echo "Missing devices under /dev/etherd/. Please run" >&2
  81. echo " aoe-mkdevs /dev/etherd" >&2
  82. echo "and try again." >&2
  83. exit 1
  84. fi
  85. # Try to set up interfaces for discovery, if any.
  86. if [ -n "$INTERFACES" ]
  87. then
  88. aoe-interfaces $INTERFACES
  89. fi
  90. aoe-discover
  91. create_fs_list
  92. if [ -n "$waitaoe" ]
  93. then
  94. echo
  95. fi
  96. if [ ! -x "/sbin/vgchange" -a -n "$LVMGROUPS" ]
  97. then
  98. echo
  99. echo "The LVM2 tools are not present. Please install lvm2 package and try again." >&2
  100. echo "We will not honour LVMGROUPS." >&2
  101. LMVGROUPS=''
  102. fi
  103. if [ -n "$LVMGROUPS" ]
  104. then
  105. echo "Assembling LVM2 groups..."
  106. for vg in "$LVMGROUPS"; do
  107. vgchange --available=y $vg
  108. done
  109. fi
  110. if [ -n "$waitaoe" ]
  111. then
  112. for mountpt in $waitaoe; do
  113. echo "Mounting $mountpt..."
  114. mount $mountpt
  115. #log_action_begin_msg "Waiting for $mountpt."
  116. done
  117. else
  118. echo "Nothing to mount."
  119. fi
  120. }
  121. do_stop() {
  122. create_fs_list
  123. if [ -n "$waitaoe" ]
  124. then
  125. for mountpt in $waitaoe; do
  126. if [ -z "`awk '{print $2}' < /proc/mounts | grep -w $mountpt$`" ];then
  127. # It's already been unmounted.
  128. continue
  129. fi
  130. echo "Unmounting $mountpt..."
  131. umount $mountpt
  132. done
  133. fi
  134. if [ -n "$LVMGROUPS" ]
  135. then
  136. for vg in "$LVMGROUPS"; do
  137. vgchange --available=n $vg
  138. done
  139. fi
  140. # Removing the module prevents LVM's "Shutting down LVM Volume Groups..."
  141. # from hanging when an LVM has been setup on a device in /dev/etherd/.
  142. modprobe --remove aoe >/dev/null 2>&1 || true
  143. }
  144. case "$1" in
  145. start|restart|reload|force-reload)
  146. echo -n "Starting $DESC: "
  147. do_start
  148. ;;
  149. stop)
  150. echo "Stopping $DESC: "
  151. do_stop
  152. ;;
  153. *)
  154. N=/etc/init.d/$NAME
  155. echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
  156. exit 1
  157. ;;
  158. esac
  159. exit 0