~ubuntu-branches/ubuntu/utopic/mariadb-5.5/utopic-security

« back to all changes in this revision

Viewing changes to packaging/rpm-oel/mysql.init

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen, Otto Kekäläinen, James Page
  • Date: 2014-03-02 01:38:26 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140302013826-z3afnfteqo86pccd
[ Otto Kekäläinen ]
* New upstream release.
* Updated Danish debconf translation (Closes: #739750).
* d/control: Added explicit Conflicts/Replaces for mysql-5.6 packages
  (Closes: #739841).
* d/control: Update for use of virtual-* packages for switching to/from
  MySQL alternatives.

[ James Page ]
* d/control: Drop Nicholas from Uploaders, MIA (Closes: #739360).
* d/control: Add libjemalloc-dev to BD's.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# mysqld        This shell script takes care of starting and stopping
 
4
#               the MySQL subsystem (mysqld).
 
5
#
 
6
# chkconfig: - 64 36
 
7
# description:  MySQL database server.
 
8
# processname: mysqld
 
9
# config: /etc/my.cnf
 
10
# pidfile: /var/run/mysqld/mysqld.pid
 
11
 
 
12
# Source function library.
 
13
. /etc/rc.d/init.d/functions
 
14
 
 
15
# Source networking configuration.
 
16
. /etc/sysconfig/network
 
17
 
 
18
 
 
19
exec="/usr/bin/mysqld_safe"
 
20
prog="mysqld"
 
21
 
 
22
# Set timeouts here so they can be overridden from /etc/sysconfig/mysqld
 
23
STARTTIMEOUT=120
 
24
STOPTIMEOUT=60
 
25
 
 
26
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
 
27
 
 
28
lockfile=/var/lock/subsys/$prog
 
29
 
 
30
 
 
31
# extract value of a MySQL option from config files
 
32
# Usage: get_mysql_option SECTION VARNAME DEFAULT
 
33
# result is returned in $result
 
34
# We use my_print_defaults which prints all options from multiple files,
 
35
# with the more specific ones later; hence take the last match.
 
36
get_mysql_option(){
 
37
        result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
 
38
        if [ -z "$result" ]; then
 
39
            # not found, use default
 
40
            result="$3"
 
41
        fi
 
42
}
 
43
 
 
44
get_mysql_option mysqld datadir "/var/lib/mysql"
 
45
datadir="$result"
 
46
get_mysql_option mysqld socket "$datadir/mysql.sock"
 
47
socketfile="$result"
 
48
get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"
 
49
errlogfile="$result"
 
50
get_mysql_option mysqld_safe pid-file "/var/run/mysqld/mysqld.pid"
 
51
mypidfile="$result"
 
52
 
 
53
 
 
54
start(){
 
55
    [ -x $exec ] || exit 5
 
56
    # check to see if it's already running
 
57
    RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
 
58
    if [ $? = 0 ]; then
 
59
        # already running, do nothing
 
60
        action $"Starting $prog: " /bin/true
 
61
        ret=0
 
62
    elif echo "$RESPONSE" | grep -q "Access denied for user"
 
63
    then
 
64
        # already running, do nothing
 
65
        action $"Starting $prog: " /bin/true
 
66
        ret=0
 
67
    else
 
68
        # prepare for start
 
69
        touch "$errlogfile"
 
70
        chown mysql:mysql "$errlogfile" 
 
71
        chmod 0640 "$errlogfile"
 
72
        [ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
 
73
        if [ ! -d "$datadir/mysql" ] ; then
 
74
            # First, make sure $datadir is there with correct permissions
 
75
            if [ ! -e "$datadir" -a ! -h "$datadir" ]
 
76
            then
 
77
                mkdir -p "$datadir" || exit 1
 
78
            fi
 
79
            chown mysql:mysql "$datadir"
 
80
            chmod 0755 "$datadir"
 
81
            [ -x /sbin/restorecon ] && /sbin/restorecon "$datadir"
 
82
            # Now create the database
 
83
            action $"Initializing MySQL database: " /usr/bin/mysql_install_db --rpm --datadir="$datadir" --user=mysql
 
84
            ret=$?
 
85
            chown -R mysql:mysql "$datadir"
 
86
            if [ $ret -ne 0 ] ; then
 
87
                return $ret
 
88
            fi
 
89
        fi
 
90
        chown mysql:mysql "$datadir"
 
91
        chmod 0755 "$datadir"
 
92
        # Pass all the options determined above, to ensure consistent behavior.
 
93
        # In many cases mysqld_safe would arrive at the same conclusions anyway
 
94
        # but we need to be sure.  (An exception is that we don't force the
 
95
        # log-error setting, since this script doesn't really depend on that,
 
96
        # and some users might prefer to configure logging to syslog.)
 
97
        # Note: set --basedir to prevent probes that might trigger SELinux
 
98
        # alarms, per bug #547485
 
99
        $exec   --datadir="$datadir" --socket="$socketfile" \
 
100
                --pid-file="$mypidfile" \
 
101
                --basedir=/usr --user=mysql >/dev/null 2>&1 &
 
102
        safe_pid=$!
 
103
        # Spin for a maximum of N seconds waiting for the server to come up;
 
104
        # exit the loop immediately if mysqld_safe process disappears.
 
105
        # Rather than assuming we know a valid username, accept an "access
 
106
        # denied" response as meaning the server is functioning.
 
107
        ret=0
 
108
        TIMEOUT="$STARTTIMEOUT"
 
109
        while [ $TIMEOUT -gt 0 ]; do
 
110
            RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1` && break
 
111
            echo "$RESPONSE" | grep -q "Access denied for user" && break
 
112
            if ! /bin/kill -0 $safe_pid 2>/dev/null; then
 
113
                echo "MySQL Daemon failed to start."
 
114
                ret=1
 
115
                break
 
116
            fi
 
117
            sleep 1
 
118
            let TIMEOUT=${TIMEOUT}-1
 
119
        done
 
120
        if [ $TIMEOUT -eq 0 ]; then
 
121
            echo "Timeout error occurred trying to start MySQL Daemon."
 
122
            ret=1
 
123
        fi
 
124
        if [ $ret -eq 0 ]; then
 
125
            action $"Starting $prog: " /bin/true
 
126
            touch $lockfile
 
127
        else
 
128
            action $"Starting $prog: " /bin/false
 
129
        fi
 
130
    fi
 
131
    return $ret
 
132
}
 
133
 
 
134
stop(){
 
135
        if [ ! -f "$mypidfile" ]; then
 
136
            # not running; per LSB standards this is "ok"
 
137
            action $"Stopping $prog: " /bin/true
 
138
            return 0
 
139
        fi
 
140
        MYSQLPID=`cat "$mypidfile"`
 
141
        if [ -n "$MYSQLPID" ]; then
 
142
            /bin/kill "$MYSQLPID" >/dev/null 2>&1
 
143
            ret=$?
 
144
            if [ $ret -eq 0 ]; then
 
145
                TIMEOUT="$STOPTIMEOUT"
 
146
                while [ $TIMEOUT -gt 0 ]; do
 
147
                    /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break
 
148
                    sleep 1
 
149
                    let TIMEOUT=${TIMEOUT}-1
 
150
                done
 
151
                if [ $TIMEOUT -eq 0 ]; then
 
152
                    echo "Timeout error occurred trying to stop MySQL Daemon."
 
153
                    ret=1
 
154
                    action $"Stopping $prog: " /bin/false
 
155
                else
 
156
                    rm -f $lockfile
 
157
                    rm -f "$socketfile"
 
158
                    action $"Stopping $prog: " /bin/true
 
159
                fi
 
160
            else
 
161
                action $"Stopping $prog: " /bin/false
 
162
            fi
 
163
        else
 
164
            # failed to read pidfile, probably insufficient permissions
 
165
            action $"Stopping $prog: " /bin/false
 
166
            ret=4
 
167
        fi
 
168
        return $ret
 
169
}
 
170
 
 
171
restart(){
 
172
    stop
 
173
    start
 
174
}
 
175
 
 
176
condrestart(){
 
177
    [ -e $lockfile ] && restart || :
 
178
}
 
179
 
 
180
 
 
181
# See how we were called.
 
182
case "$1" in
 
183
  start)
 
184
    start
 
185
    ;;
 
186
  stop)
 
187
    stop
 
188
    ;;
 
189
  status)
 
190
    status -p "$mypidfile" $prog
 
191
    ;;
 
192
  restart)
 
193
    restart
 
194
    ;;
 
195
  condrestart|try-restart)
 
196
    condrestart
 
197
    ;;
 
198
  reload)
 
199
    exit 3
 
200
    ;;
 
201
  force-reload)
 
202
    restart
 
203
    ;;
 
204
  *)
 
205
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
 
206
    exit 2
 
207
esac
 
208
 
 
209
exit $?