/rgmanager/src/resources/mysql.sh

https://github.com/LarsFronius/resource-agents · Shell · 213 lines · 160 code · 34 blank · 19 comment · 18 complexity · 4501a53f3fc996c0733f7efa57e7872c MD5 · raw file

  1. #!/bin/bash
  2. #
  3. # Copyright (C) 1997-2003 Sistina Software, Inc. All rights reserved.
  4. # Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. #
  20. export LC_ALL=C
  21. export LANG=C
  22. export PATH=/bin:/sbin:/usr/bin:/usr/sbin
  23. . $(dirname $0)/ocf-shellfuncs
  24. . $(dirname $0)/utils/config-utils.sh
  25. . $(dirname $0)/utils/messages.sh
  26. . $(dirname $0)/utils/ra-skelet.sh
  27. declare MYSQL_MYSQLD=/usr/bin/mysqld_safe
  28. declare MYSQL_ipAddress
  29. declare MYSQL_pid_file="`generate_name_for_pid_file`"
  30. verify_all()
  31. {
  32. clog_service_verify $CLOG_INIT
  33. if [ -z "$OCF_RESKEY_name" ]; then
  34. clog_service_verify $CLOG_FAILED "Invalid Name Of Service"
  35. return $OCF_ERR_ARGS
  36. fi
  37. if [ -z "$OCF_RESKEY_service_name" ]; then
  38. clog_service_verify $CLOG_FAILED_NOT_CHILD
  39. return $OCF_ERR_ARGS
  40. fi
  41. if [ -z "$OCF_RESKEY_config_file" ]; then
  42. clog_check_file_exist $CLOG_FAILED_INVALID "$OCF_RESKEY_config_file"
  43. clog_service_verify $CLOG_FAILED
  44. return $OCF_ERR_ARGS
  45. fi
  46. if [ ! -r "$OCF_RESKEY_config_file" ]; then
  47. clog_check_file_exist $CLOG_FAILED_NOT_READABLE $OCF_RESKEY_config_file
  48. clog_service_verify $CLOG_FAILED
  49. return $OCF_ERR_ARGS
  50. fi
  51. if [ -z "$MYSQL_pid_file" ]; then
  52. clog_service_verify $CLOG_FAILED "Invalid name of PID file"
  53. return $OCF_ERR_ARGS
  54. fi
  55. clog_service_verify $CLOG_SUCCEED
  56. return 0
  57. }
  58. start()
  59. {
  60. if status; then
  61. ocf_log info "Starting Service $OCF_RESOURCE_INSTANCE > Already running"
  62. return $OCF_SUCCESS
  63. fi
  64. clog_service_start $CLOG_INIT
  65. create_pid_directory
  66. check_pid_file "$MYSQL_pid_file"
  67. if [ $? -ne 0 ]; then
  68. clog_check_pid $CLOG_FAILED "$MYSQL_pid_file"
  69. clog_service_start $CLOG_FAILED
  70. return $OCF_ERR_GENERIC
  71. fi
  72. if [ -n "$OCF_RESKEY_listen_address" ]; then
  73. MYSQL_ipAddress="$OCF_RESKEY_listen_address"
  74. else
  75. clog_looking_for $CLOG_INIT "IP Address"
  76. get_service_ip_keys "$OCF_RESKEY_service_name"
  77. ip_addresses=`build_ip_list`
  78. if [ -n "$ip_addresses" ]; then
  79. for i in $ip_addresses; do
  80. MYSQL_ipAddress="$i"
  81. break;
  82. done
  83. else
  84. clog_looking_for $CLOG_FAILED_NOT_FOUND "IP Address"
  85. fi
  86. fi
  87. clog_looking_for $CLOG_SUCCEED "IP Address"
  88. $MYSQL_MYSQLD --defaults-file="$OCF_RESKEY_config_file" \
  89. --pid-file="$MYSQL_pid_file" \
  90. --bind-address="$MYSQL_ipAddress" \
  91. $OCF_RESKEY_mysqld_options > /dev/null 2>&1 &
  92. if [ $? -ne 0 ]; then
  93. clog_service_start $CLOG_FAILED
  94. return $OCF_ERR_GENERIC
  95. fi
  96. declare i=$OCF_RESKEY_startup_wait
  97. while [ "$i" -gt 0 ]; do
  98. if [ -f "$MYSQL_pid_file" ]; then
  99. break;
  100. fi
  101. sleep 1
  102. let i=$i-1
  103. done
  104. if [ "$i" -eq 0 ]; then
  105. clog_service_start $CLOG_FAILED_TIMEOUT
  106. return $OCF_ERR_GENERIC
  107. fi
  108. clog_service_start $CLOG_SUCCEED
  109. return 0;
  110. }
  111. stop()
  112. {
  113. clog_service_stop $CLOG_INIT
  114. stop_generic "$MYSQL_pid_file" "$OCF_RESKEY_shutdown_wait"
  115. if [ $? -ne 0 ]; then
  116. clog_service_stop $CLOG_FAILED
  117. return $OCF_ERR_GENERIC
  118. fi
  119. clog_service_stop $CLOG_SUCCEED
  120. return 0;
  121. }
  122. status()
  123. {
  124. clog_service_status $CLOG_INIT
  125. status_check_pid "$MYSQL_pid_file"
  126. case $? in
  127. $OCF_NOT_RUNNING)
  128. clog_service_status $CLOG_FAILED "$MYSQL_pid_file"
  129. return $OCF_NOT_RUNNING
  130. ;;
  131. 0)
  132. clog_service_status $CLOG_SUCCEED
  133. exit 0
  134. ;;
  135. *)
  136. clog_service_status $CLOG_FAILED "$MYSQL_pid_file"
  137. return $OCF_ERR_GENERIC
  138. ;;
  139. esac
  140. if [ $? -ne 0 ]; then
  141. clog_service_status $CLOG_FAILED "$MYSQL_pid_file"
  142. return $OCF_ERR_GENERIC
  143. fi
  144. clog_service_status $CLOG_SUCCEED
  145. return 0
  146. }
  147. case $1 in
  148. meta-data)
  149. cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'`
  150. exit 0
  151. ;;
  152. validate-all)
  153. verify_all
  154. exit $?
  155. ;;
  156. start)
  157. verify_all && start
  158. exit $?
  159. ;;
  160. stop)
  161. verify_all && stop
  162. exit $?
  163. ;;
  164. status|monitor)
  165. verify_all
  166. status
  167. exit $?
  168. ;;
  169. restart)
  170. verify_all
  171. stop
  172. start
  173. exit $?
  174. ;;
  175. *)
  176. echo "Usage: $0 {start|stop|status|monitor|restart|meta-data|validate-all}"
  177. exit $OCF_ERR_UNIMPLEMENTED
  178. ;;
  179. esac