~percona-dev/percona-server/release-5.5.11-20.2-fix-bug-764138

« back to all changes in this revision

Viewing changes to build/debian/percona-server-server-5.5.mysql.init

  • Committer: Ignacio Nin
  • Date: 2011-03-13 17:18:23 UTC
  • mfrom: (33.3.17 release-5.5.8-20)
  • Revision ID: ignacio.nin@percona.com-20110313171823-m06xs104nekulywb
Merge changes from release-5.5.8-20 to 5.5.9

Merge changes from the release branch of 5.5.8 to 5.5.9. These include
the HandlerSocket and UDF directories and the building scripts.

Show diffs side-by-side

added added

removed removed

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