This commit is contained in:
2025-11-01 21:18:29 +08:00
parent 35478d43d6
commit a607719b46
119 changed files with 815 additions and 1221 deletions

View File

@@ -31,10 +31,10 @@ function Print {
}
function Quit {
Print killing greatsql ...
Print killing greatsqld ...
greatsqladmin shutdown || true
while :; do
pkill -f greatsqld && Print killing greatsql ... || break
pkill -f greatsqld && Print killing greatsqld ... || break
sleep 1
done
Print Container stopped.
@@ -57,20 +57,35 @@ function Init {
}
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"
local sql_file=
local sql_files=
greatsql -e "CREATE USER docker@localhost IDENTIFIED BY 'China_19\$(10)!'"
greatsql -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
greatsql < $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) \
&& greatsqladmin flush-logs
done
}
function StartProc {
Print Starting greatsql ...
greatsqld &
PIDS="$PIDS $!"
while sleep 1; do
@@ -79,12 +94,13 @@ function StartProc {
done
echo
[ -z "$INIT_FLAG" ] || ImportInitSql
SideCar &
PIDS="$PIDS $!"
Print GreatSQL is ready for connections.
}
function Main {
local pid=
Print Starting greatsql ...
Init
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM