Saltstack Official Galera Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 9 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #!/bin/bash
  2. #
  3. ### BEGIN INIT INFO
  4. # Provides: mysql
  5. # Required-Start: $remote_fs $syslog
  6. # Required-Stop: $remote_fs $syslog
  7. # Should-Start: $network $named $time
  8. # Should-Stop: $network $named $time
  9. # Default-Start: 2 3 4 5
  10. # Default-Stop: 0 1 6
  11. # Short-Description: Start and stop the mysql database server daemon
  12. # Description: Controls the main MySQL database server daemon "mysqld"
  13. # and its wrapper script "mysqld_safe".
  14. ### END INIT INFO
  15. #
  16. set -e
  17. set -u
  18. ${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
  19. test -x /usr/sbin/mysqld || exit 0
  20. . /lib/lsb/init-functions
  21. SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
  22. CONF=/etc/mysql/my.cnf
  23. # MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
  24. # priority can be overriden and "-s" adds output to stderr
  25. ERR_LOGGER="logger -p daemon.err -t /etc/init.d/mysql -i"
  26. # Safeguard (relative paths, core dumps..)
  27. cd /
  28. umask 077
  29. # mysqladmin likes to read /root/.my.cnf. This is usually not what I want
  30. # as many admins e.g. only store a password without a username there and
  31. # so break my scripts.
  32. export HOME=/etc/mysql/
  33. ## Fetch a particular option from mysql's invocation.
  34. #
  35. # Usage: void mysqld_get_param option
  36. mysqld_get_param() {
  37. /usr/sbin/mysqld --print-defaults \
  38. | tr " " "\n" \
  39. | grep -- "--$1" \
  40. | tail -n 1 \
  41. | cut -d= -f2
  42. }
  43. # Determine parameters once per script invocation
  44. datadir=`mysqld_get_param datadir`
  45. [ -z "$datadir" ] && datadir="/var/lib/mysql"
  46. pidfile=`mysqld_get_param pid_file`
  47. #[ -z "$pidfile" ] && pidfile="$datadir/$(hostname).pid"
  48. #JPavlik tcp cloud fix for init script
  49. pidfile="/var/lib/mysql/mysqld.pid"
  50. ## Do some sanity checks before even trying to start mysqld.
  51. sanity_checks() {
  52. # check for config file
  53. if [ ! -r /etc/mysql/my.cnf ]; then
  54. log_warning_msg "$0: WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz"
  55. echo "WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz" | $ERR_LOGGER
  56. fi
  57. # check for diskspace shortage
  58. if LC_ALL=C BLOCKSIZE= df --portability $datadir/. | tail -n 1 | awk '{ exit ($4>4096) }'; then
  59. log_failure_msg "$0: ERROR: The partition with $datadir is too full!"
  60. echo "ERROR: The partition with $datadir is too full!" | $ERR_LOGGER
  61. exit 1
  62. fi
  63. }
  64. ## Checks if there is a server running and if so if it is accessible.
  65. #
  66. # check_alive insists on a pingable server
  67. # check_dead also fails if there is a lost mysqld in the process list
  68. #
  69. # Usage: boolean mysqld_status [check_alive|check_dead] [warn|nowarn]
  70. mysqld_status() {
  71. # ping_output=`$MYADMIN ping 2>&1`; ping_alive=$(( ! $? ))
  72. ps_alive=0
  73. if [ -f "$pidfile" ] && ps `cat $pidfile` >/dev/null 2>&1; then ps_alive=1; fi
  74. if [ "$1" = "check_alive" -a $ps_alive = 1 ] ||
  75. [ "$1" = "check_dead" -a $ps_alive = 0 ]; then
  76. return 0 # EXIT_SUCCESS
  77. else
  78. if [ "$2" = "warn" ]; then
  79. # echo -e "$ps_alive processes alive and '$MYADMIN ping' resulted in\n$ping_output\n" | $ERR_LOGGER -p daemon.debug
  80. echo -e "$ps_alive processes alive\n" | $ERR_LOGGER -p daemon.debug
  81. fi
  82. return 1 # EXIT_FAILURE
  83. fi
  84. }
  85. #
  86. # main()
  87. #
  88. cmd=${1:-''}
  89. [ $# -ge 1 ] && shift
  90. other_args="$*"
  91. case "$cmd" in
  92. 'start')
  93. sanity_checks;
  94. # Start daemon
  95. log_daemon_msg "Starting MySQL database server" "mysqld"
  96. if mysqld_status check_alive nowarn; then
  97. log_progress_msg "already running"
  98. log_end_msg 0
  99. else
  100. # Could be removed during boot
  101. test -e /var/run/mysqld || install -m 755 -o mysql -g root -d /var/run/mysqld
  102. # Check for additional wsrep options
  103. WSREP_OPTS=${WSREP_OPTS:-""}
  104. WSREP_PROVIDER=${WSREP_PROVIDER:-""}
  105. WSREP_CLUSTER_ADDRESS=${WSREP_CLUSTER_ADDRESS:-""}
  106. test -n "$WSREP_PROVIDER" && \
  107. WSREP_OPTS="$WSREP_OPTS --wsrep_provider=$WSREP_PROVIDER"
  108. test -n "$WSREP_CLUSTER_ADDRESS" && \
  109. WSREP_OPTS="$WSREP_OPTS --wsrep_cluster_address=$WSREP_CLUSTER_ADDRESS"
  110. # Start MySQL!.
  111. /usr/bin/mysqld_safe $WSREP_OPTS $other_args > /dev/null 2>&1 &
  112. # 6s was reported in #352070 to be too few when using ndbcluster
  113. for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
  114. sleep 1
  115. if mysqld_status check_alive nowarn ; then break; fi
  116. log_progress_msg "."
  117. done
  118. if mysqld_status check_alive warn; then
  119. log_end_msg 0
  120. # Now start mysqlcheck or whatever the admin wants.
  121. # output=$(/etc/mysql/debian-start)
  122. # [ -n "$output" ] && log_action_msg "$output"
  123. else
  124. log_end_msg 1
  125. log_failure_msg "Please take a look at the syslog"
  126. fi
  127. fi
  128. ;;
  129. 'stop')
  130. # * As a passwordless mysqladmin (e.g. via ~/.my.cnf) must be possible
  131. # at least for cron, we can rely on it here, too. (although we have
  132. # to specify it explicit as e.g. sudo environments points to the normal
  133. # users home and not /root)
  134. log_daemon_msg "Stopping MySQL database server" "mysqld"
  135. if ! mysqld_status check_dead nowarn; then
  136. log_daemon_msg "Killing MySQL database server by signal" "mysqld"
  137. pid=$(cat $pidfile || echo 0)
  138. if [ $pid -eq 0 ]; then
  139. log_failure_msg "Failed to get MySQL server pid"
  140. exit 1
  141. fi
  142. kill -15 $pid
  143. server_down=
  144. for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
  145. log_progress_msg "."
  146. sleep 1
  147. if mysqld_status check_dead nowarn; then server_down=1; break; fi
  148. done
  149. fi
  150. if ! mysqld_status check_dead warn; then
  151. log_end_msg 1
  152. log_failure_msg "Please stop MySQL manually and read /usr/share/doc/mysql-server-5.1/README.Debian.gz!"
  153. exit -1
  154. else
  155. log_end_msg 0
  156. fi
  157. ;;
  158. 'restart')
  159. set +e; $SELF stop; set -e
  160. $SELF start $other_args
  161. ;;
  162. 'reload'|'force-reload')
  163. log_daemon_msg "Reloading MySQL database server" "mysqld"
  164. $MYADMIN reload
  165. log_end_msg 0
  166. ;;
  167. 'status')
  168. if mysqld_status check_alive nowarn; then
  169. # log_action_msg "$($MYADMIN version)"
  170. log_action_msg "MySQL is running (PID: $(cat $pidfile))"
  171. else
  172. log_action_msg "MySQL is stopped."
  173. exit 3
  174. fi
  175. ;;
  176. *)
  177. echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
  178. exit 1
  179. ;;
  180. esac