Cause mysql init script to honor settings in my.cnf (bz#76051)
This commit is contained in:
parent
f681a34ca5
commit
f44a0e3fa7
60
mysql.init
60
mysql.init
@ -18,23 +18,55 @@
|
|||||||
|
|
||||||
prog="MySQL"
|
prog="MySQL"
|
||||||
|
|
||||||
datadir="/var/lib/mysql"
|
# extract value of a MySQL option from /etc/my.cnf
|
||||||
|
# Usage: get_mysql_option FILE VARNAME DEFAULT
|
||||||
|
# result is returned in $result
|
||||||
|
# Ugly as this is, it knows nothing of option file sections ...
|
||||||
|
get_mysql_option(){
|
||||||
|
result=`sed -n "s/^[ \t]*$2[ \t]*=[ \t]*//p" "$1" 2>/dev/null | tail -n 1`
|
||||||
|
if [ -z "$result" ]; then
|
||||||
|
# not found, use default
|
||||||
|
result="$3"
|
||||||
|
else
|
||||||
|
# found, still have to deal with quoting and end-of-line comments
|
||||||
|
dequoted=`echo "$result" | sed "s/^'\([^']*\)'.*$/\1/"`
|
||||||
|
if [ x"$dequoted" != x"$result" ]; then
|
||||||
|
result="$dequoted"
|
||||||
|
else
|
||||||
|
dequoted=`echo "$result" | sed 's/^"\([^"]*\)".*$/\1/'`
|
||||||
|
if [ x"$dequoted" != x"$result" ]; then
|
||||||
|
result="$dequoted"
|
||||||
|
else
|
||||||
|
result=`echo "$result" | sed 's/^\([^ \t#]*\).*$/\1/'`
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_mysql_option /etc/my.cnf datadir "/var/lib/mysql"
|
||||||
|
datadir="$result"
|
||||||
|
get_mysql_option /etc/my.cnf socket "$datadir/mysql.sock"
|
||||||
|
socketfile="$result"
|
||||||
|
get_mysql_option /etc/my.cnf err-log "/var/log/mysqld.log"
|
||||||
|
errlogfile="$result"
|
||||||
|
get_mysql_option /etc/my.cnf pid-file "/var/run/mysqld/mysqld.pid"
|
||||||
|
mypidfile="$result"
|
||||||
|
|
||||||
start(){
|
start(){
|
||||||
touch /var/log/mysqld.log
|
touch "$errlogfile"
|
||||||
chown mysql:mysql /var/log/mysqld.log
|
chown mysql:mysql "$errlogfile"
|
||||||
chmod 0640 /var/log/mysqld.log
|
chmod 0640 "$errlogfile"
|
||||||
[ -x /sbin/restorecon ] && /sbin/restorecon /var/log/mysqld.log
|
[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
|
||||||
if [ ! -d $datadir/mysql ] ; then
|
if [ ! -d "$datadir/mysql" ] ; then
|
||||||
action $"Initializing MySQL database: " /usr/bin/mysql_install_db
|
action $"Initializing MySQL database: " /usr/bin/mysql_install_db
|
||||||
ret=$?
|
ret=$?
|
||||||
chown -R mysql:mysql $datadir
|
chown -R mysql:mysql "$datadir"
|
||||||
if [ $ret -ne 0 ] ; then
|
if [ $ret -ne 0 ] ; then
|
||||||
return $ret;
|
return $ret
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
chown -R mysql:mysql $datadir
|
chown -R mysql:mysql "$datadir"
|
||||||
chmod 0755 $datadir
|
chmod 0755 "$datadir"
|
||||||
/usr/bin/mysqld_safe --defaults-file=/etc/my.cnf >/dev/null 2>&1 &
|
/usr/bin/mysqld_safe --defaults-file=/etc/my.cnf >/dev/null 2>&1 &
|
||||||
ret=$?
|
ret=$?
|
||||||
# Spin for a maximum of N seconds waiting for the server to come up.
|
# Spin for a maximum of N seconds waiting for the server to come up.
|
||||||
@ -62,21 +94,21 @@ start(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
stop(){
|
stop(){
|
||||||
/bin/kill `cat /var/run/mysqld/mysqld.pid 2> /dev/null ` > /dev/null 2>&1
|
/bin/kill `cat "$mypidfile" 2>/dev/null ` >/dev/null 2>&1
|
||||||
ret=$?
|
ret=$?
|
||||||
if [ $ret -eq 0 ]; then
|
if [ $ret -eq 0 ]; then
|
||||||
|
sleep 2
|
||||||
|
rm -f /var/lock/subsys/mysqld
|
||||||
|
rm -f "$socketfile"
|
||||||
action $"Stopping $prog: " /bin/true
|
action $"Stopping $prog: " /bin/true
|
||||||
else
|
else
|
||||||
action $"Stopping $prog: " /bin/false
|
action $"Stopping $prog: " /bin/false
|
||||||
fi
|
fi
|
||||||
[ $ret -eq 0 ] && rm -f /var/lock/subsys/mysqld
|
|
||||||
[ $ret -eq 0 ] && rm -f $datadir/mysql.sock
|
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
restart(){
|
restart(){
|
||||||
stop
|
stop
|
||||||
sleep 2
|
|
||||||
start
|
start
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user