2016-12-16 23:26:52 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# mysql
|
|
|
|
#
|
|
|
|
|
|
|
|
MYSQL_LIB="/var/lib/mysql"
|
|
|
|
MYSQL_RUN="/run/mysql"
|
2020-02-04 02:21:57 +01:00
|
|
|
MYSQL_PIDFILE="$MYSQL_RUN/mysqld.pid"
|
2020-02-04 02:21:58 +01:00
|
|
|
MYSQL_LOG="/var/log/mysql"
|
|
|
|
MYSQL_LOGFILE="$MYSQL_LOG/mysqld.log"
|
2016-12-16 23:26:52 +01:00
|
|
|
MYSQL_BIN="/usr/bin"
|
|
|
|
|
|
|
|
wait_for_ready() {
|
|
|
|
WAIT_DELAY=5
|
|
|
|
while [ $WAIT_DELAY -gt 0 ]; do
|
|
|
|
if $MYSQL_BIN/mysqladmin ping > /dev/null 2>&1; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
: $((WAIT_DELAY -= 1))
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
2020-02-04 02:21:56 +01:00
|
|
|
# stderr is redirected to prevent a warning
|
|
|
|
# if mysql lib directory doesn't exist
|
|
|
|
if [ `ls -1 $MYSQL_LIB 2> /dev/null | wc -l` = 0 ] ; then
|
2016-12-16 23:26:52 +01:00
|
|
|
printf "Creating mysql system tables ... "
|
2020-02-04 02:21:59 +01:00
|
|
|
$MYSQL_BIN/mysql_install_db --basedir=/usr \
|
2016-12-16 23:26:52 +01:00
|
|
|
--datadir=$MYSQL_LIB > /dev/null 2>&1
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "FAIL"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-02-04 02:21:59 +01:00
|
|
|
chown -R mysql:mysql $MYSQL_LIB
|
2016-12-16 23:26:52 +01:00
|
|
|
echo "OK"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# mysqld runs as user mysql, but /run is only writable by root
|
|
|
|
# so create a subdirectory for mysql.
|
|
|
|
install -d -o mysql -g root -m 0755 $MYSQL_RUN
|
|
|
|
|
2020-02-04 02:21:58 +01:00
|
|
|
# Also create logging directory as user mysql.
|
|
|
|
install -d -o mysql -g root -m 0755 $MYSQL_LOG
|
|
|
|
|
2016-12-16 23:26:52 +01:00
|
|
|
# We don't use start-stop-daemon because mysqld has its own
|
|
|
|
# wrapper script.
|
|
|
|
printf "Starting mysql ... "
|
2020-02-04 02:21:57 +01:00
|
|
|
$MYSQL_BIN/mysqld_safe --pid-file=$MYSQL_PIDFILE --user=mysql \
|
2020-02-04 02:21:58 +01:00
|
|
|
--log-error=$MYSQL_LOGFILE > /dev/null 2>&1 &
|
2016-12-16 23:26:52 +01:00
|
|
|
wait_for_ready
|
|
|
|
[ $? = 0 ] && echo "OK" || echo "FAIL"
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
printf "Stopping mysql ... "
|
2020-02-04 02:21:57 +01:00
|
|
|
if [ -f $MYSQL_PIDFILE ]; then
|
|
|
|
kill `cat $MYSQL_PIDFILE` > /dev/null 2>&1
|
2016-12-16 23:26:52 +01:00
|
|
|
[ $? = 0 ] && echo "OK" || echo "FAIL"
|
|
|
|
else
|
|
|
|
echo "FAIL"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
restart() {
|
|
|
|
stop
|
|
|
|
sleep 1
|
|
|
|
start
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
restart
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 {start|stop|restart}"
|
|
|
|
;;
|
|
|
|
esac
|