This commit is contained in:
colben 2024-12-24 13:40:15 +08:00
parent 4a0e19cc8b
commit 17fca60282
28 changed files with 50 additions and 38 deletions

View File

@ -1,8 +1,8 @@
FROM alpine:3.17
FROM alpine:3.20
MAINTAINER Colben colbenlee@gmail.com
ADD --chown=root:root /ADD/ /etc/
RUN echo -e 'https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.17/main\n\
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.17/community\n\
RUN echo -e 'https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.20/main\n\
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.20/community\n\
' > /etc/apk/repositories \
&& apk update \
&& apk add --no-cache bash curl coreutils iproute2 \

View File

@ -57,7 +57,7 @@ function Main {
# ModifyConf
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -82,7 +82,7 @@ function Main {
ModifyConf
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -106,7 +106,7 @@ function Main {
ChangeSysConf
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -146,7 +146,7 @@ function Main {
ChangeSysConf
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -167,7 +167,7 @@ function Main {
ChangeOwner
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -32,9 +32,9 @@ function Print {
function Quit {
Print killing greatsql ...
mysqladmin shutdown || true
greatsqladmin shutdown || true
while :; do
pkill -f mysqld && Print killing greatsql ... || break
pkill -f greatsqld && Print killing greatsql ... || break
sleep 1
done
Print Container stopped.
@ -71,7 +71,7 @@ function ImportInitSql {
}
function StartProc {
mysqld &
greatsqld &
PIDS="$PIDS $!"
while sleep 1; do
[ -e $SOCK_FILE ] && break || echo -n .
@ -88,7 +88,7 @@ function Main {
Init
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -29,7 +29,9 @@ gpgcheck=0\n\
&& rm -f /tmp/greatsql-devel* /tmp/greatsql-mysql-router-* \
&& rpm -ivh /tmp/greatsql-*.rpm \
&& ln -s /usr/bin/mysql /usr/bin/greatsql \
&& ln -s /usr/sbin/mysqld /usr/sbin/greatsqld \
&& ln -s /usr/bin/mysqldump /usr/bin/greatsqldump \
&& ln -s /usr/bin/mysqladmin /usr/bin/greatsqladmin \
&& rm -rf /usr/sbin/mysqld-debug \
/var/cache/yum \
/var/lib/yum \
@ -55,10 +57,6 @@ lock-wait-timeout = 3600\n\
open-files-limit = 65535\n\
back-log = 1024\n\
max-connections = 512\n\
lock-wait-timeout = 3600\n\
open-files-limit = 65535\n\
back-log = 1024\n\
max-connections = 512\n\
max-connect-errors = 1000000\n\
table-open-cache = 1024\n\
table-definition-cache = 1024\n\

View File

@ -65,7 +65,7 @@ function Main {
ModifyConf
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -45,7 +45,7 @@ function Main {
local pid=
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -93,7 +93,7 @@ function Main {
ChangeOwner
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -73,7 +73,7 @@ function Main {
InstallPlugin
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -82,7 +82,7 @@ function Main {
Init
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -63,7 +63,7 @@ function Main {
Init
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -52,7 +52,7 @@ 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"
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
@ -63,6 +63,18 @@ function ImportInitSql {
fi
}
function SideCar {
local day= 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 &
@ -73,6 +85,8 @@ function StartProc {
done
echo
[ -z "$INIT_FLAG" ] || ImportInitSql
SideCar &
PIDS="$PIDS $!"
Print MySQL is ready for connections.
}
@ -81,7 +95,7 @@ function Main {
Init
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -79,7 +79,7 @@ function Main {
ChangeOwner
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -84,7 +84,7 @@ function Main {
ChangeOwner
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -84,7 +84,7 @@ function Main {
ChangeOwner
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -47,7 +47,7 @@ function SideCar {
local day= last_day=$(date +%d)
local md5= last_md5=$(find /etc/nginx/ -type f -name "*.conf" \
| xargs -I ^ md5sum ^ | md5sum)
while sleep 10; do
while sleep 8; do
day=$(date +%d) \
&& [ "$day" != "$last_day" ] \
&& last_day=$day \
@ -79,7 +79,7 @@ function Main {
ChangeOwner
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -240,7 +240,7 @@ function Main {
Init
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -135,7 +135,7 @@ function Main {
Init
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -49,7 +49,7 @@ function Main {
local pid=
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -51,7 +51,7 @@ function Main {
local pid=
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -55,7 +55,7 @@ function Main {
RestoreConf
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -65,7 +65,7 @@ function Main {
CreateFtpUser
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -59,7 +59,7 @@ function Main {
ModifyConf
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -158,7 +158,7 @@ function Main {
InitDB
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done

View File

@ -72,7 +72,7 @@ function Main {
ModifyConf
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
while [ -z "$GOT_SIGTERM" ] && sleep 2; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done