~ubuntu-branches/ubuntu/wily/mysql-5.6/wily

« back to all changes in this revision

Viewing changes to packaging/deb-utopic/mysql-community-server.mysql.init

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2015-04-16 20:07:10 UTC
  • mto: (1.3.9 vivid-proposed)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20150416200710-pcrsa022082zj46k
Tags: upstream-5.6.24
ImportĀ upstreamĀ versionĀ 5.6.24

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 $time
 
8
# Should-Stop:       $network $time
 
9
# Default-Start:     2 3 4 5
 
10
# Default-Stop:      0 1 6
 
11
# Short-Description: Start/ Stop MySQL Community Server daemon
 
12
# Description:       This service script facilitates startup and shutdown of
 
13
#                    mysqld daemon throught its wrapper script mysqld_safe
 
14
### END INIT INFO
 
15
#
 
16
 
 
17
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
 
18
#
 
19
# This program is free software; you can redistribute it and/or modify
 
20
# it under the terms of the GNU General Public License as published by
 
21
# the Free Software Foundation; version 2 of the License.
 
22
#
 
23
# This program is distributed in the hope that it will be useful,
 
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
26
# GNU General Public License for more details.
 
27
#
 
28
# You should have received a copy of the GNU General Public License
 
29
# along with this program; if not, write to the Free Software
 
30
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
31
 
 
32
. /lib/lsb/init-functions
 
33
 
 
34
cd /
 
35
umask 077
 
36
 
 
37
MYSQLDATA=/var/lib/mysql
 
38
VERSION=$(mysqld --version | grep mysqld | cut -d' ' -f4)
 
39
 
 
40
get_pcount () {
 
41
        PSCOUNT=$(ps -ef | grep "/usr/sbin/mysqld" | wc -l)
 
42
        echo "${PSCOUNT}"
 
43
}
 
44
 
 
45
server_stop () {
 
46
        PSCOUNT=$(get_pcount)
 
47
        COUNT=0
 
48
        while :; do
 
49
                COUNT=$(( COUNT+1 ))
 
50
                echo -n .
 
51
                if [ "${PSCOUNT}" -eq 1 ];
 
52
                then
 
53
                        echo
 
54
                        break
 
55
                fi
 
56
                if [ "${COUNT}" -gt 15 ];
 
57
                then
 
58
                        echo
 
59
                        return 1
 
60
                fi
 
61
                PSCOUNT=$(get_pcount)
 
62
                sleep 1
 
63
        done
 
64
        return 0
 
65
}
 
66
 
 
67
case "$1" in
 
68
  'start')
 
69
        PSCOUNT=$(get_pcount)
 
70
        if [ "${PSCOUNT}" -gt 1 ];
 
71
        then
 
72
                log_action_msg "A MySQL Server is already started"
 
73
        else
 
74
                MYSQLRUN=/var/run/mysqld
 
75
                MYSQLDATA=/var/lib/mysql
 
76
                MYSQLLOG=/var/log/mysql
 
77
 
 
78
                if [ ! -d ${MYSQLDATA} -a ! -L ${MYSQLDATA} ];
 
79
                then
 
80
                        mkdir ${MYSQLDATA}
 
81
                        chown mysql:mysql ${MYSQLDATA}
 
82
                        chmod 750 ${MYSQLDATA}
 
83
                fi
 
84
 
 
85
                if [ ! -d "${MYSQLDATA}/mysql" -a ! -L "${MYSQLDATA}/mysql" ];
 
86
                then
 
87
                        mkdir ${MYSQLDATA}/mysql
 
88
                        chown mysql:mysql ${MYSQLDATA}/mysql
 
89
                        chmod 750 ${MYSQLDATA}/mysql
 
90
                fi
 
91
 
 
92
                if [ ! "$(ls -A ${MYSQLDATA}/mysql)" ];
 
93
                then
 
94
                        mysql_install_db --user=mysql > /dev/null
 
95
                fi
 
96
 
 
97
                if [ ! -d ${MYSQLLOG} -a ! -L ${MYSQLLOG} ];
 
98
                then
 
99
                        mkdir ${MYSQLLOG}
 
100
                        chown mysql:adm ${MYSQLLOG}
 
101
                        chmod 750 ${MYSQLLOG}
 
102
                        touch ${MYSQLLOG}/error.log
 
103
                        chmod 640 ${MYSQLLOG}/error.log
 
104
                        chown mysql:adm ${MYSQLLOG}/error.log
 
105
                fi
 
106
 
 
107
                if [ ! -d "${MYSQLRUN}" -a ! -L "${MYSQLRUN}" ];
 
108
                then
 
109
                        mkdir ${MYSQLRUN}
 
110
                        chown mysql:mysql ${MYSQLRUN}
 
111
                        chmod 755 ${MYSQLRUN}
 
112
                fi
 
113
 
 
114
                /lib/init/apparmor-profile-load usr.sbin.mysqld
 
115
 
 
116
                su - mysql -s /bin/bash -c "mysqld_safe > /dev/null &"
 
117
                for i in 1 2 3 4 5 6;
 
118
                do
 
119
                        sleep 1
 
120
                        echo -n .
 
121
                done
 
122
                echo
 
123
                PSCOUNT=$(get_pcount)
 
124
                if [ "${PSCOUNT}" -gt 1 ];
 
125
                then
 
126
                        log_action_msg "MySQL Community Server ${VERSION} is started"
 
127
                else
 
128
                        log_action_msg "MySQL Community Server ${VERSION} did not start. Please check logs for more details."
 
129
                fi
 
130
        fi
 
131
        ;;
 
132
 
 
133
  'stop')
 
134
        PSCOUNT=$(get_pcount)
 
135
        if [ "${PSCOUNT}" -gt 1 ];
 
136
        then
 
137
                killall -15 mysqld
 
138
                server_stop
 
139
                if [ "$?" -eq 0 ];
 
140
                then
 
141
                        log_action_msg "MySQL Community Server ${VERSION} is stopped"
 
142
                else
 
143
                        log_action_msg "Attempt to shutdown MySQL Community Server ${VERSION} timed out"
 
144
                fi
 
145
        else
 
146
                log_action_msg "MySQL Community Server ${VERSION} is already stopped"
 
147
        fi
 
148
        ;;
 
149
 
 
150
  'restart'|'reload'|'force-reload')
 
151
        log_action_msg "Stopping MySQL Community Server ${VERSION}"
 
152
        $0 stop
 
153
        log_action_msg "Re-starting MySQL Community Server ${VERSION}"
 
154
        $0 start
 
155
        ;;
 
156
 
 
157
  'status')
 
158
        PSCOUNT=$(get_pcount)
 
159
        if [ ${PSCOUNT} -gt 1 ];
 
160
        then
 
161
                log_action_msg "MySQL Community Server ${VERSION} is running"
 
162
        else
 
163
                log_action_msg "MySQL Community Server ${VERSION} is not running"
 
164
                exit 3
 
165
        fi
 
166
        ;;
 
167
 
 
168
  *)
 
169
        echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
 
170
        exit 1
 
171
        ;;
 
172
esac
 
173
 
 
174
exit 0