update
This commit is contained in:
100
greatsql/ADD/ccmd
Executable file
100
greatsql/ADD/ccmd
Executable file
@@ -0,0 +1,100 @@
|
||||
#!/bin/bash
|
||||
|
||||
##################################################
|
||||
# Mount file #
|
||||
# - /etc/my.cnf #
|
||||
# Mount dir #
|
||||
# - LOG_DIR #
|
||||
# - DATA_DIR #
|
||||
# - BINLOG_DIR #
|
||||
##################################################
|
||||
|
||||
set -euo pipefail
|
||||
export LANG=en_US.UTF-8
|
||||
export LD_PRELOAD=/usr/lib64/libjemalloc.so
|
||||
export THP_SETTING=
|
||||
trap Quit EXIT
|
||||
|
||||
PIDS=
|
||||
GOT_SIGTERM=
|
||||
LOG_DIR='/var/log/mysql'
|
||||
DATA_DIR='/var/lib/mysql'
|
||||
BINLOG_DIR='/var/lib/mysql-bin'
|
||||
SOCK_FILE='/run/mysqld/mysqld.sock'
|
||||
PID_FILE='/run/mysqld/mysqld.pid'
|
||||
INIT_FLAG=
|
||||
|
||||
function Print {
|
||||
local file=/dev/null
|
||||
[ '-f' = "$1" ] && file=$2 && shift && shift
|
||||
date +"[%F %T] $*" | tee -a $file
|
||||
}
|
||||
|
||||
function Quit {
|
||||
Print killing greatsql ...
|
||||
mysqladmin shutdown || true
|
||||
while :; do
|
||||
pkill -f mysqld && Print killing greatsql ... || break
|
||||
sleep 1
|
||||
done
|
||||
Print Container stopped.
|
||||
test -n "$GOT_SIGTERM"
|
||||
}
|
||||
|
||||
function Init {
|
||||
echo never > /sys/kernel/mm/transparent_hugepage/enabled \
|
||||
&& echo never > /sys/kernel/mm/transparent_hugepage/defrag \
|
||||
&& THP_SETTING=never \
|
||||
|| Print Failed to disable THP, consider privileged container.
|
||||
rm -f ${SOCK_FILE}* ${PID_FILE}
|
||||
chown -R mysql:mysql $LOG_DIR $BINLOG_DIR $DATA_DIR
|
||||
chmod 0750 $LOG_DIR
|
||||
if [ ! -d "$DATA_DIR/mysql" ]; then
|
||||
Print Initing greatsql db files ...
|
||||
mysqld_pre_systemd
|
||||
INIT_FLAG=1
|
||||
fi
|
||||
}
|
||||
|
||||
function ImportInitSql {
|
||||
local sql_file= sql_files=
|
||||
mysql -e "CREATE USER docker@localhost IDENTIFIED BY 'China_19\$(10)!'"
|
||||
mysql -e "GRANT 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 StartProc {
|
||||
mysqld &
|
||||
PIDS="$PIDS $!"
|
||||
while sleep 1; do
|
||||
[ -e $SOCK_FILE ] && break || echo -n .
|
||||
[ ! -e /proc/$! ] && echo && Print unexpected error! && exit
|
||||
done
|
||||
echo
|
||||
[ -z "$INIT_FLAG" ] || ImportInitSql
|
||||
Print GreatSQL is ready for connections.
|
||||
}
|
||||
|
||||
function Main {
|
||||
local pid=
|
||||
Print Starting greatsql ...
|
||||
Init
|
||||
StartProc
|
||||
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
|
||||
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
|
||||
for pid in $PIDS; do
|
||||
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Start here
|
||||
Main
|
||||
|
Reference in New Issue
Block a user