update
This commit is contained in:
@@ -18,9 +18,9 @@ GOT_SIGTERM=
|
||||
LOG_DIR='/var/log/mysql'
|
||||
DATA_DIR='/var/lib/mysql'
|
||||
BINLOG_DIR='/var/lib/mysql-bin'
|
||||
INIT_FLAG=${INIT_FLAG:-}
|
||||
SOCK_FILE='/run/mysqld/mysqld.sock'
|
||||
PID_FILE='/run/mysqld/mysqld.pid'
|
||||
INIT_FLAG=
|
||||
|
||||
function Print {
|
||||
local file=/dev/null
|
||||
@@ -30,7 +30,7 @@ function Print {
|
||||
|
||||
function Quit {
|
||||
Print killing mysqld ...
|
||||
mysqladmin shutdown --wait-for-all-slaves || true
|
||||
mysqladmin shutdown || true
|
||||
while :; do
|
||||
pkill -f mysqld && Print killing mysqld ... || break
|
||||
sleep 1
|
||||
@@ -49,9 +49,37 @@ function Init {
|
||||
fi
|
||||
}
|
||||
|
||||
function StartProc {
|
||||
function ImportInitSql {
|
||||
local sql_file=
|
||||
local sql_files=
|
||||
Print Securing database ...
|
||||
mysql_secure_installation <<< "$(echo -e '\nn\nn\n\n\n\n\n')" > /dev/null
|
||||
mysql -e "CREATE USER docker@localhost IDENTIFIED BY 'China_19\$(10)!'"
|
||||
mysql -e "GRANT RELOAD,SHUTDOWN ON *.* TO docker@localhost"
|
||||
if sql_files="$(ls $LOG_DIR/init_sql/*.sql 2>/dev/null)"; then
|
||||
Print Importing the sql files ...
|
||||
for sql_file in $sql_files; do
|
||||
Print Importing $sql_file ...
|
||||
mysql < $sql_file
|
||||
done
|
||||
Print Imported all sql files successfully.
|
||||
fi
|
||||
}
|
||||
|
||||
function SideCar {
|
||||
local day=
|
||||
local last_day=$(date +%d)
|
||||
while sleep 8; do
|
||||
day=$(date +%d) \
|
||||
&& [ "$day" != "$last_day" ] \
|
||||
&& last_day=$day \
|
||||
&& find $LOG_DIR -type f -name "*.log" \
|
||||
| xargs -I ^ mv -f ^ ^.$(date +%F -d yesterday) \
|
||||
&& mysqladmin flush-logs
|
||||
done
|
||||
}
|
||||
|
||||
function StartProc {
|
||||
Print Starting mysql ...
|
||||
mysqld -u mysql &
|
||||
PIDS="$PIDS $!"
|
||||
@@ -60,20 +88,9 @@ function StartProc {
|
||||
[ ! -e /proc/$! ] && echo && Print unexpected error! && exit
|
||||
done
|
||||
echo
|
||||
if [ -n "$INIT_FLAG" ]; then
|
||||
Print Securing database ...
|
||||
mysql_secure_installation <<< "$(echo -e '\nn\nn\n\n\n\n\n')" > /dev/null
|
||||
mysql -e "CREATE USER docker@localhost IDENTIFIED BY 'China_19\$(10)!'"
|
||||
mysql -e "GRANT SHUTDOWN ON *.* TO docker@localhost"
|
||||
if sql_files="$(ls $DATA_DIR/init_sql/*.sql 2>/dev/null)"; then
|
||||
Print Importing the sql files ...
|
||||
for sql_file in $sql_files; do
|
||||
Print Importing $sql_file ...
|
||||
mysql < $sql_file
|
||||
done
|
||||
Print Imported all sql files successfully.
|
||||
fi
|
||||
fi
|
||||
[ -z "$INIT_FLAG" ] || ImportInitSql
|
||||
SideCar &
|
||||
PIDS="$PIDS $!"
|
||||
Print MySQL is ready for connections.
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user