aoetools.init 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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-2007. Under GPLv2.
  11. #
  12. # Support for LVM and other mount points contributed by Glen W. Mabey.
  13. #
  14. ### BEGIN INIT INFO
  15. # Provides: aoe
  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. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  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 ] ; then
  32. . /etc/default/aoetools
  33. fi
  34. set -e
  35. create_fs_list() {
  36. # We start with a list from /etc/default/aoetools.
  37. waitaoe="$AOEMOUNTS"
  38. [ -f /etc/fstab ] || return
  39. #
  40. # Read through fstab line by line. If it contains /dev/etherd, set the flag
  41. # for mounting file systems over AoE.
  42. #
  43. exec 9<&0 </etc/fstab
  44. while read DEV MTPT FSTYPE OPTS REST
  45. do
  46. case "$OPTS" in
  47. noauto|*,noauto|noauto,*|*,noauto,*)
  48. continue
  49. ;;
  50. esac
  51. case "$DEV" in
  52. ""|\#*)
  53. continue
  54. ;;
  55. /dev/etherd/*)
  56. waitaoe="$waitaoe $MTPT"
  57. esac
  58. done
  59. exec 0<&9 9<&-
  60. }
  61. do_start() {
  62. # We exit if the user does not want us to try this.
  63. if [ "$INTERFACES" = "none" ]
  64. then
  65. echo "not started."
  66. exit 0
  67. fi
  68. # Usually aoe is a module, so we will try to load it.
  69. if [ -n "$INTERFACES" ]
  70. 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 ]
  79. then
  80. echo
  81. echo "Missing devices under /dev/etherd/. Please run" >&2
  82. echo " aoe-mkdevs /dev/etherd" >&2
  83. echo "and try again." >&2
  84. exit 1
  85. fi
  86. # Try to set up interfaces for discovery, if any.
  87. if [ -n "$INTERFACES" ]
  88. then
  89. aoe-interfaces $INTERFACES
  90. fi
  91. aoe-discover
  92. create_fs_list
  93. if [ -n "$waitaoe" ]
  94. then
  95. echo
  96. fi
  97. if [ ! -x "/sbin/vgchange" -a -n "$LVMGROUPS" ]
  98. then
  99. echo
  100. echo "The LVM2 tools are not present. Please install lvm2 package and try again." >&2
  101. echo "We will not honour LVMGROUPS." >&2
  102. LMVGROUPS=''
  103. fi
  104. if [ -n "$LVMGROUPS" ]
  105. then
  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. fi
  118. }
  119. do_stop() {
  120. create_fs_list
  121. if [ -n "$waitaoe" ]
  122. then
  123. for mountpt in $waitaoe; do
  124. echo "Unmounting $mountpt..."
  125. umount $mountpt
  126. done
  127. fi
  128. if [ -n "$LVMGROUPS" ]
  129. then
  130. for vg in "$LVMGROUPS"; do
  131. vgchange --available=n $vg
  132. done
  133. fi
  134. # Removing the module prevents LVM's "Shutting down LVM Volume Groups..."
  135. # from hanging when an LVM has been setup on a device in /dev/etherd/.
  136. modprobe --remove aoe >/dev/null 2>&1 || true
  137. }
  138. case "$1" in
  139. start|restart|reload|force-reload)
  140. echo -n "Starting $DESC: "
  141. do_start
  142. ;;
  143. stop)
  144. echo -n "Stopping $DESC: "
  145. do_stop
  146. ;;
  147. *)
  148. N=/etc/init.d/$NAME
  149. echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
  150. exit 1
  151. ;;
  152. esac
  153. exit 0