aoetools.init 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. modprobe aoe >/dev/null 2>&1 || true
  70. # Also, if udev is being used, the /dev/etherd devices
  71. # are not created until aoe module insertion, so...
  72. sleep 1 # ...we give udev a chance to populate /dev/etherd/.
  73. if [ ! -c /dev/etherd/discover ]
  74. then
  75. echo
  76. echo "Missing devices under /dev/etherd/. Please run" >&2
  77. echo " aoe-mkdevs /dev/etherd" >&2
  78. echo "and try again." >&2
  79. exit 1
  80. fi
  81. # Try to set up interfaces for discovery, if any.
  82. if [ -n "$INTERFACES" ]
  83. then
  84. aoe-interfaces $INTERFACES
  85. fi
  86. aoe-discover
  87. create_fs_list
  88. if [ -n "$waitaoe" ]
  89. then
  90. echo
  91. fi
  92. if [ ! -x "/sbin/vgchange" -a -n "$LVMGROUPS" ]
  93. then
  94. echo
  95. echo "The LVM2 tools are not present. Please install lvm2 package and try again." >&2
  96. echo "We will not honour LVMGROUPS." >&2
  97. LMVGROUPS=""
  98. fi
  99. if [ -n "$LVMGROUPS" ]
  100. then
  101. for vg in "$LVMGROUPS"; do
  102. vgchange --available=y $vg
  103. done
  104. fi
  105. if [ -n "$waitaoe" ]
  106. then
  107. for mountpt in $waitaoe; do
  108. echo "Mounting $mountpt..."
  109. mount $mountpt
  110. #log_action_begin_msg "Waiting for $mountpt."
  111. done
  112. fi
  113. }
  114. do_stop() {
  115. create_fs_list
  116. if [ -n "$waitaoe" ]
  117. then
  118. for mountpt in $waitaoe; do
  119. echo "Unmounting $mountpt..."
  120. umount $mountpt
  121. done
  122. fi
  123. if [ -n "$LVMGROUPS" ]
  124. then
  125. for vg in "$LVMGROUPS"; do
  126. vgchange --available=n $vg
  127. done
  128. fi
  129. # Removing the module prevents LVM's "Shutting down LVM Volume Groups..."
  130. # from hanging when an LVM has been setup on a device in /dev/etherd/.
  131. modprobe --remove aoe >/dev/null 2>&1 || true
  132. }
  133. case "$1" in
  134. start|restart|reload|force-reload)
  135. echo -n "Starting $DESC: "
  136. do_start
  137. ;;
  138. stop)
  139. echo -n "Stopping $DESC: "
  140. do_stop
  141. ;;
  142. *)
  143. N=/etc/init.d/$NAME
  144. echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
  145. exit 1
  146. ;;
  147. esac
  148. exit 0