- #!/bin/bash
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- set -e
- set -u
- ${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
-
- test -x /usr/sbin/mysqld || exit 0
-
- . /lib/lsb/init-functions
-
- SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
- CONF=/etc/mysql/my.cnf
-
-
-
- ERR_LOGGER="logger -p daemon.err -t /etc/init.d/mysql -i"
-
-
- cd /
- umask 077
-
-
-
-
- export HOME=/etc/mysql/
-
-
-
-
- mysqld_get_param() {
- /usr/sbin/mysqld --print-defaults \
- | tr " " "\n" \
- | grep -- "--$1" \
- | tail -n 1 \
- | cut -d= -f2
- }
-
-
- datadir=`mysqld_get_param datadir`
- [ -z "$datadir" ] && datadir="/var/lib/mysql"
- pidfile=`mysqld_get_param pid_file`
-
-
-
- pidfile="/var/lib/mysql/mysqld.pid"
-
- sanity_checks() {
-
- if [ ! -r /etc/mysql/my.cnf ]; then
- log_warning_msg "$0: WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz"
- echo "WARNING: /etc/mysql/my.cnf cannot be read. See README.Debian.gz" | $ERR_LOGGER
- fi
-
-
- if LC_ALL=C BLOCKSIZE= df --portability $datadir/. | tail -n 1 | awk '{ exit ($4>4096) }'; then
- log_failure_msg "$0: ERROR: The partition with $datadir is too full!"
- echo "ERROR: The partition with $datadir is too full!" | $ERR_LOGGER
- exit 1
- fi
- }
-
-
-
-
-
-
-
- mysqld_status() {
-
-
- ps_alive=0
- if [ -f "$pidfile" ] && ps `cat $pidfile` >/dev/null 2>&1; then ps_alive=1; fi
- if [ "$1" = "check_alive" -a $ps_alive = 1 ] ||
- [ "$1" = "check_dead" -a $ps_alive = 0 ]; then
- return 0
- else
- if [ "$2" = "warn" ]; then
-
- echo -e "$ps_alive processes alive\n" | $ERR_LOGGER -p daemon.debug
- fi
- return 1
- fi
- }
-
-
-
-
-
-
- cmd=${1:-''}
- [ $# -ge 1 ] && shift
- other_args="$*"
-
- case "$cmd" in
- 'start')
- sanity_checks;
-
- log_daemon_msg "Starting MySQL database server" "mysqld"
- if mysqld_status check_alive nowarn; then
- log_progress_msg "already running"
- log_end_msg 0
- else
-
- test -e /var/run/mysqld || install -m 755 -o mysql -g root -d /var/run/mysqld
-
-
- WSREP_OPTS=${WSREP_OPTS:-""}
- WSREP_PROVIDER=${WSREP_PROVIDER:-""}
- WSREP_CLUSTER_ADDRESS=${WSREP_CLUSTER_ADDRESS:-""}
- test -n "$WSREP_PROVIDER" && \
- WSREP_OPTS="$WSREP_OPTS --wsrep_provider=$WSREP_PROVIDER"
- test -n "$WSREP_CLUSTER_ADDRESS" && \
- WSREP_OPTS="$WSREP_OPTS --wsrep_cluster_address=$WSREP_CLUSTER_ADDRESS"
-
-
- /usr/bin/mysqld_safe $WSREP_OPTS $other_args > /dev/null 2>&1 &
-
-
- for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14; do
- sleep 1
- if mysqld_status check_alive nowarn ; then break; fi
- log_progress_msg "."
- done
- if mysqld_status check_alive warn; then
- log_end_msg 0
-
-
-
- else
- log_end_msg 1
- log_failure_msg "Please take a look at the syslog"
- fi
- fi
- ;;
-
- 'stop')
-
-
-
-
- log_daemon_msg "Stopping MySQL database server" "mysqld"
- if ! mysqld_status check_dead nowarn; then
- log_daemon_msg "Killing MySQL database server by signal" "mysqld"
- pid=$(cat $pidfile || echo 0)
- if [ $pid -eq 0 ]; then
- log_failure_msg "Failed to get MySQL server pid"
- exit 1
- fi
- kill -15 $pid
- server_down=
- for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
- log_progress_msg "."
- sleep 1
- if mysqld_status check_dead nowarn; then server_down=1; break; fi
- done
- fi
-
- if ! mysqld_status check_dead warn; then
- log_end_msg 1
- log_failure_msg "Please stop MySQL manually and read /usr/share/doc/mysql-server-5.1/README.Debian.gz!"
- exit -1
- else
- log_end_msg 0
- fi
- ;;
-
- 'restart')
- set +e; $SELF stop; set -e
- $SELF start $other_args
- ;;
-
- 'reload'|'force-reload')
- log_daemon_msg "Reloading MySQL database server" "mysqld"
- $MYADMIN reload
- log_end_msg 0
- ;;
-
- 'status')
- if mysqld_status check_alive nowarn; then
-
- log_action_msg "MySQL is running (PID: $(cat $pidfile))"
- else
- log_action_msg "MySQL is stopped."
- exit 3
- fi
- ;;
-
- *)
- echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
- exit 1
- ;;
- esac
|