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
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
17
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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.
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.
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
32
. /lib/lsb/init-functions
37
MYSQLDATA=/var/lib/mysql
38
VERSION=$(mysqld --version | grep mysqld | cut -d' ' -f4)
41
PSCOUNT=$(ps -ef | grep "/usr/sbin/mysqld" | wc -l)
51
if [ "${PSCOUNT}" -eq 1 ];
56
if [ "${COUNT}" -gt 15 ];
70
if [ "${PSCOUNT}" -gt 1 ];
72
log_action_msg "A MySQL Server is already started"
74
MYSQLRUN=/var/run/mysqld
75
MYSQLDATA=/var/lib/mysql
76
MYSQLLOG=/var/log/mysql
78
if [ ! -d ${MYSQLDATA} -a ! -L ${MYSQLDATA} ];
81
chown mysql:mysql ${MYSQLDATA}
82
chmod 750 ${MYSQLDATA}
85
if [ ! -d "${MYSQLDATA}/mysql" -a ! -L "${MYSQLDATA}/mysql" ];
87
mkdir ${MYSQLDATA}/mysql
88
chown mysql:mysql ${MYSQLDATA}/mysql
89
chmod 750 ${MYSQLDATA}/mysql
92
if [ ! "$(ls -A ${MYSQLDATA}/mysql)" ];
94
mysql_install_db --user=mysql > /dev/null
97
if [ ! -d ${MYSQLLOG} -a ! -L ${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
107
if [ ! -d "${MYSQLRUN}" -a ! -L "${MYSQLRUN}" ];
110
chown mysql:mysql ${MYSQLRUN}
111
chmod 755 ${MYSQLRUN}
114
/lib/init/apparmor-profile-load usr.sbin.mysqld
116
su - mysql -s /bin/bash -c "mysqld_safe > /dev/null &"
117
for i in 1 2 3 4 5 6;
123
PSCOUNT=$(get_pcount)
124
if [ "${PSCOUNT}" -gt 1 ];
126
log_action_msg "MySQL Community Server ${VERSION} is started"
128
log_action_msg "MySQL Community Server ${VERSION} did not start. Please check logs for more details."
134
PSCOUNT=$(get_pcount)
135
if [ "${PSCOUNT}" -gt 1 ];
141
log_action_msg "MySQL Community Server ${VERSION} is stopped"
143
log_action_msg "Attempt to shutdown MySQL Community Server ${VERSION} timed out"
146
log_action_msg "MySQL Community Server ${VERSION} is already stopped"
150
'restart'|'reload'|'force-reload')
151
log_action_msg "Stopping MySQL Community Server ${VERSION}"
153
log_action_msg "Re-starting MySQL Community Server ${VERSION}"
158
PSCOUNT=$(get_pcount)
159
if [ ${PSCOUNT} -gt 1 ];
161
log_action_msg "MySQL Community Server ${VERSION} is running"
163
log_action_msg "MySQL Community Server ${VERSION} is not running"
169
echo "Usage: $SELF start|stop|restart|reload|force-reload|status"