aoetools.init 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. echo "Assembling LVM2 groups..."
  107. for vg in "$LVMGROUPS"; do
  108. vgchange --available=y $vg
  109. done
  110. fi
  111. if [ -n "$waitaoe" ]
  112. then
  113. for mountpt in $waitaoe; do
  114. echo "Mounting $mountpt..."
  115. mount $mountpt
  116. #log_action_begin_msg "Waiting for $mountpt."
  117. done
  118. else
  119. echo "Nothing to mount."
  120. fi
  121. }
  122. do_stop() {
  123. create_fs_list
  124. if [ -n "$waitaoe" ]
  125. then
  126. for mountpt in $waitaoe; do
  127. echo "Unmounting $mountpt..."
  128. umount $mountpt
  129. done
  130. fi
  131. if [ -n "$LVMGROUPS" ]
  132. then
  133. for vg in "$LVMGROUPS"; do
  134. vgchange --available=n $vg
  135. done
  136. fi
  137. # Removing the module prevents LVM's "Shutting down LVM Volume Groups..."
  138. # from hanging when an LVM has been setup on a device in /dev/etherd/.
  139. modprobe --remove aoe >/dev/null 2>&1 || true
  140. }
  141. case "$1" in
  142. start|restart|reload|force-reload)
  143. echo -n "Starting $DESC: "
  144. do_start
  145. ;;
  146. stop)
  147. echo -n "Stopping $DESC: "
  148. do_stop
  149. ;;
  150. *)
  151. N=/etc/init.d/$NAME
  152. echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
  153. exit 1
  154. ;;
  155. esac
  156. exit 0