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

View File

@@ -3,27 +3,14 @@ FROM harbor.colben.cn/general/rocky$ARCH:8
MAINTAINER Colben colbenlee@gmail.com
ARG BUNDLE_FILE
ADD --chown=root:root /ADD/ /opt/
RUN echo -e 'fs.file-max = 1000000\n\
net.core.somaxconn = 32768\n\
net.ipv4.tcp_syncookies = 0\n\
vm.overcommit_memory = 1\n\
' >> /etc/sysctl.conf \
&& echo -e '\n\
mysql soft nofile 65535\n\
mysql hard nofile 65535\n\
mysql soft stack 32768\n\
mysql hard stack 32768\n\
mysql soft nproc 65535\n\
mysql hard nproc 65535\n\
' >> /etc/security/limits.conf \
&& echo -e '[epel]\n\
RUN echo -e '[epel]\n\
name=Extra Packages for Enterprise Linux $releasever - $basearch\n\
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/Everything/$basearch\n\
enabled=1\n\
gpgcheck=0\n\
' > /etc/yum.repos.d/epel.repo \
&& dnf makecache \
&& dnf -y install xz pkg-config perl libaio-devel numactl-devel numactl-libs net-tools openssl openssl-devel jemalloc jemalloc-devel perl-Data-Dumper perl-Digest-MD5 python2 perl-JSON perl-Test-Simple \
&& microdnf makecache \
&& microdnf install xz pkg-config perl libaio-devel numactl-devel numactl-libs net-tools openssl openssl-devel jemalloc jemalloc-devel perl-Data-Dumper perl-Digest-MD5 python2 perl-JSON perl-Test-Simple \
&& curl -LO http://10.11.0.1:10080/$BUNDLE_FILE \
&& tar xf $BUNDLE_FILE -C /tmp/ \
&& rm -f /tmp/greatsql-devel* /tmp/greatsql-mysql-router-* \
@@ -33,7 +20,7 @@ gpgcheck=0\n\
&& ln -s /usr/bin/mysqldump /usr/bin/greatsqldump \
&& ln -s /usr/bin/mysqladmin /usr/bin/greatsqladmin \
&& rm -rf /usr/sbin/mysqld-debug \
/var/cache/dnf \
/var/cache/yum \
/var/lib/dnf \
/var/log/* \
/etc/my.cnf.d \
@@ -99,6 +86,19 @@ lower-case-table-names = 1\n\
[mysqladmin]\n\
user = docker\n\
password = China_19$(10)!\n\
' > /etc/mysql/my.cnf
' > /etc/mysql/my.cnf \
&& echo -e 'fs.file-max = 1000000\n\
net.core.somaxconn = 32768\n\
net.ipv4.tcp_syncookies = 0\n\
vm.overcommit_memory = 1\n\
' >> /etc/sysctl.conf \
&& echo -e '\n\
mysql soft nofile 65535\n\
mysql hard nofile 65535\n\
mysql soft stack 32768\n\
mysql hard stack 32768\n\
mysql soft nproc 65535\n\
mysql hard nproc 65535\n\
' >> /etc/security/limits.conf
CMD ["/opt/ccmd"]

View File

@@ -9,7 +9,8 @@ export LANG=en_US.UTF-8
[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)"
ROOT_DIR="$(cd $(dirname $0) && pwd)"
IMAGE="harbor.colben.cn/general/greatsql$ARCH:8"
TAG=$1
IMAGE="harbor.colben.cn/general/greatsql$ARCH:$TAG"
BUNDLE_FILE=
if [ -t 0 ]; then
@@ -24,7 +25,7 @@ fi
function Quit {
local exitCode=$?
pkill -f '^python2 -m SimpleHTTPServer 10080$' || true
pkill -f '^python -m http.server 10080' || true
[ 0 -ne $exitCode ] && Error Failed to build or push image!
[ -z "${END:-}" ] && echo && Error Interrupted manually!
Print Succeeded to build and push image.
@@ -46,14 +47,14 @@ function Update {
Warn Check files ...
cd /release/RUNTIME
if [ -z "$ARCH" ]; then
BUNDLE_FILE=greatsql-8.0.32-26.1.el8.amd64.rpm-bundle.tar.xz
BUNDLE_FILE=greatsql-8.0.32-27.1.el8.amd64.rpm-bundle.tar.xz
elif [ '-aarch64' == "$ARCH" ]; then
BUNDLE_FILE=greatsql-8.0.32-26.1.el8.arm64.rpm-bundle.tar.xz
BUNDLE_FILE=greatsql-8.0.32-27.1.el8.arm64.rpm-bundle.tar.xz
else
Error Unknown arch: $ARCH!
fi
[ -e $BUNDLE_FILE ] || Error Not found $BUNDLE_FILE!
python2 -m SimpleHTTPServer 10080 &>/dev/null &
/usr/libexec/platform-python -m http.server 10080 &>/dev/null &
}
function Build {
@@ -63,7 +64,7 @@ function Build {
&& Warn Removing image $IMAGE ... \
&& docker rmi $IMAGE
Warn Building image: $IMAGE ...
docker build --force-rm --build-arg ARCH="$ARCH" --build-arg BUNDLE_FILE="$BUNDLE_FILE" -t $IMAGE -f Dockerfile-greatsql8 .
docker build --force-rm --build-arg ARCH="$ARCH" --build-arg BUNDLE_FILE="$BUNDLE_FILE" -t $IMAGE -f Dockerfile-$TAG .
YesOrNo Push image: $IMAGE? && docker push $IMAGE
}