ocfs2.initd 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2011 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. depend() {
  5. need net localmount
  6. before netmount
  7. }
  8. check_modules_config() {
  9. local MODULES=$1
  10. local CONFIGS=$2
  11. local MODULE
  12. local retval=0
  13. for MODULE in ${MODULES}; do
  14. if ! ls -1 /sys/module | egrep -q "^${MODULE}$"; then
  15. retval=1
  16. fi
  17. done
  18. if [ ${retval} -eq 1 ] && [ -e /proc/config.gz ]; then
  19. retval=0
  20. for MODULE in ${CONFIGS}; do
  21. if ! gzip -dc /proc/config.gz | egrep -q "^CONFIG_${MODULE}=y$"; then
  22. retval=1
  23. fi
  24. done
  25. fi
  26. return ${retval}
  27. }
  28. check_modules() {
  29. check_modules_config "ocfs2_dlmfs ocfs2 ocfs2_dlm ocfs2_nodemanager" "OCFS2_FS OCFS2_FS_O2CB" && check_modules_config configfs CONFIGFS_FS && return 0
  30. if ! egrep -q '\s*ocfs2\s*$' /proc/filesystems || ! egrep -q '\s*ocfs2_dlmfs\s*$' /proc/filesystems; then
  31. ewarn "One or more required modules are not loaded."
  32. ewarn "Make sure you have "
  33. ewarn " - placed ocfs, dlmfs and configfs into /etc/modules.autoload.d/kernel-2.6 or built directly into the kernel."
  34. ewarn "For a (in)complete documentation, read /usr/share/doc/ocfs-<version>/INSTALL.GENTOO.bz2"
  35. fi
  36. return 1
  37. }
  38. check_pseudofs() {
  39. local retval=0
  40. local HASMOUNT="mount -l -t"
  41. if [ -z "`${HASMOUNT} configfs`" ] ; then
  42. retval=1
  43. fi
  44. if [ -z "`${HASMOUNT} ocfs2_dlmfs`" ] ; then
  45. retval=1
  46. fi
  47. if [ ${retval} -eq 1 ]; then
  48. ewarn "One or more pseudo-filesystes are not mounted."
  49. ewarn "Make sure you have following lines in your /etc/fstab:"
  50. ewarn "none /sys/kernel/config configfs defaults 0 0"
  51. ewarn "none /sys/kernel/dlm ocfs2_dlmfs defaults 0 0"
  52. fi
  53. return ${retval}
  54. }
  55. start() {
  56. check_modules || return $?
  57. check_pseudofs || return $?
  58. einfo "Starting OCFS2 cluster"
  59. for cluster in ${OCFS2_CLUSTER}; do
  60. ebegin " - ${cluster}"
  61. /sbin/o2cb_ctl -H -n ${cluster} -t cluster -a online=yes >/dev/null 2>&1
  62. eend $?
  63. # Some heartbeat tweaks to prevent self-fencing quite so much during heavy load.
  64. # http://oss.oracle.com/projects/ocfs2/dist/documentation/ocfs2_faq.html
  65. # How long to wait before a node is considered dead from lack of network activity.
  66. echo $OCFS2_IDLE_TIMEOUT_MS > /sys/kernel/config/cluster/${cluster}/idle_timeout_ms
  67. # How often we should attempt to send heartbeats.
  68. echo $OCFS2_KEEPALIVE_DELAY_MS > /sys/kernel/config/cluster/${cluster}/keepalive_delay_ms
  69. echo $OCFS2_RECONNECT_DELAY_MS > /sys/kernel/config/cluster/${cluster}/reconnect_delay_ms
  70. # How many interations before a node is considered dead from lack of IO activity.
  71. # (dead_threshold - 1) * 2s
  72. echo $OCFS2_DEAD_THRESHOLD > /sys/kernel/config/cluster/${cluster}/heartbeat/dead_threshold
  73. done
  74. sleep 2
  75. }
  76. stop() {
  77. # Shamelesly stolen from netmount
  78. local ret
  79. ebegin "Unmounting OCFS2 filesystems"
  80. [ -z "$(umount -art ocfs2 2>&1)" ]
  81. ret=$?
  82. eend ${ret} "Failed to simply unmount filesystems"
  83. [ ${ret} -eq 0 ] && return 0
  84. declare -a siglist=( "TERM" "KILL" "KILL" )
  85. local retry=0
  86. local remaining="go"
  87. while [ -n "${remaining}" -a ${retry} -lt 3 ]
  88. do
  89. remaining="$(awk '$3 ~ /'ocfs2'/ { if ($2 != "/") print $2 }' /proc/mounts | sort -r)"
  90. IFS=$'\n'
  91. set -- ${remaining//\\040/ }
  92. unset IFS
  93. [ -z "${remaining}" ] && break
  94. ebegin $'\t'"Unmounting ocfs2 filesystems (retry #$((retry+1)))"
  95. /bin/fuser -k -${siglist[$((retry++))]} -m "$@" &>/dev/null
  96. sleep 5
  97. umount "$@" &>/dev/null
  98. eend $? $'\t'"Failed to unmount filesystems"
  99. done
  100. einfo "Stopping OCFS2 cluster"
  101. for cluster in ${OCFS_CLUSTERS}; do
  102. ebegin " - ${cluster}"
  103. /sbin/o2cb_ctl -H -n ${cluster} -t cluster -a online=no >/dev/null 2>&1
  104. eend $?
  105. done
  106. }