From 6895daf9f11443e3ae32fa585407890cacdf7f2a Mon Sep 17 00:00:00 2001 From: xiao Date: Tue, 5 Nov 2024 19:00:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 6 +++-- arm64/Dockerfile | 6 +++-- arm64/bt.sh | 63 ++++++++++++++++++++++++++++++++++++++------- arm64/init_mysql.sh | 41 +++++++++++++++++++++++++++++ bt.sh | 63 ++++++++++++++++++++++++++++++++++++++------- init_mysql.sh | 41 +++++++++++++++++++++++++++++ 6 files changed, 196 insertions(+), 24 deletions(-) create mode 100644 arm64/init_mysql.sh create mode 100644 init_mysql.sh diff --git a/Dockerfile b/Dockerfile index 5d1f85f..6209b55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,11 +24,13 @@ ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 ENV LC_CTYPE en_US.UTF-8 -# 复制 bt.sh 文件 +# 复制启动脚本 COPY bt.sh /bt.sh +COPY init_mysql.sh /init_mysql.sh -# 转换 bt.sh 文件的换行符 +# 转换启动脚本 RUN dos2unix /bt.sh +RUN dos2unix /init_mysql.sh # 设置构建参数 ARG RANDOM_NAME diff --git a/arm64/Dockerfile b/arm64/Dockerfile index 5017a47..f12c62b 100644 --- a/arm64/Dockerfile +++ b/arm64/Dockerfile @@ -25,11 +25,13 @@ RUN locale-gen en_US.UTF-8 \ && export LC_CTYPE=en_US.UTF-8 \ && update-locale -# 复制 bt.sh 文件 +# 复制启动脚本 COPY bt.sh /bt.sh +COPY init_mysql.sh /init_mysql.sh -# 转换 bt.sh 文件的换行符 +# 转换启动脚本 RUN dos2unix /bt.sh +RUN dos2unix /init_mysql.sh # 设置构建参数 ARG RANDOM_NAME diff --git a/arm64/bt.sh b/arm64/bt.sh index 63c5af9..101e6c9 100644 --- a/arm64/bt.sh +++ b/arm64/bt.sh @@ -6,28 +6,71 @@ init_path=/etc/init.d Root_Path=`cat /var/bt_setupPath.conf` Setup_Path=$Root_Path/server/mysql Data_Path=$Root_Path/server/data +O_pl=$(cat /www/server/panel/data/o.pl) soft_start(){ - ${init_path}/nginx start - ${init_path}/php-fpm-83 start - ${init_path}/bt restart + # 扫描并启动所有服务 + init_scripts=$(ls ${init_path}) + for script in ${init_scripts}; do + case "${script}" in + "bt"|"mysqld"|"nginx"|"httpd") + continue + ;; + esac + + ${init_path}/${script} start + done + + if [ -f ${init_path}/nginx ]; then + ${init_path}/nginx start + elif [ -f ${init_path}/httpd ]; then + ${init_path}/httpd start + fi + + ${init_path}/bt stop + ${init_path}/bt start + pkill crond /sbin/crond + + chmod 600 /etc/ssh/ssh_host_* /usr/sbin/sshd -D & } +init_mysql(){ + if [ "${O_pl}" != "docker_btlamp_d12" ] && [ "${O_pl}" != "docker_btlnmp_d12" ];then + return + fi + if [ -d "${Data_Path}" ]; then + check_z=$(ls "${Data_Path}") + echo "check_z:" + echo ${check_z} + if [[ ! -z "${check_z}" ]]; then + echo "check_z is not empty" + return + fi + fi + if [ -f /init_mysql.sh ] && [ -d "${Setup_Path}" ];then + sh /init_mysql.sh + rm -f /init_mysql.sh + fi +} + is_empty_Data(){ - return `ls -A ${Data_Path}/|wc -w` + return "$(ls -A ${Data_Path}/|wc -w)" } start_mysql(){ - chown -R mysql:mysql ${Data_Path} - chgrp -R mysql ${Setup_Path}/. - ${init_path}/mysqld start - rm -f /init_mysql.sh + if [ -d "${Setup_Path}" ] && [ -f "${init_path}/mysqld" ];then + chown -R mysql:mysql ${Data_Path} + chgrp -R mysql ${Setup_Path}/. + ${init_path}/mysqld start + fi } -soft_start > /dev/null is_empty_Data > /dev/null +init_mysql > /dev/null start_mysql > /dev/null -tail -f /dev/null +soft_start > /dev/null +#tail -f /dev/null +${init_path}/bt log \ No newline at end of file diff --git a/arm64/init_mysql.sh b/arm64/init_mysql.sh new file mode 100644 index 0000000..f773276 --- /dev/null +++ b/arm64/init_mysql.sh @@ -0,0 +1,41 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +Root_Path=`cat /var/bt_setupPath.conf` +Setup_Path=$Root_Path/server/mysql +Data_Path=$Root_Path/server/data + +Mysql_Initialize(){ + if [ -d "${Data_Path}" ]; then + check_z=$(ls "${Data_Path}") + if [[ ! -z "${check_z}" ]]; then + return + fi + fi + + mkdir -p ${Data_Path} + chown -R mysql:mysql ${Data_Path} + chgrp -R mysql ${Setup_Path}/. + + ${Setup_Path}/bin/mysqld --initialize-insecure --basedir=${Setup_Path} --datadir=${Data_Path} --user=mysql + + cat > /etc/ld.so.conf.d/mysql.conf< /dev/null is_empty_Data > /dev/null +init_mysql > /dev/null start_mysql > /dev/null -tail -f /dev/null +soft_start > /dev/null +#tail -f /dev/null +${init_path}/bt log \ No newline at end of file diff --git a/init_mysql.sh b/init_mysql.sh new file mode 100644 index 0000000..f773276 --- /dev/null +++ b/init_mysql.sh @@ -0,0 +1,41 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +Root_Path=`cat /var/bt_setupPath.conf` +Setup_Path=$Root_Path/server/mysql +Data_Path=$Root_Path/server/data + +Mysql_Initialize(){ + if [ -d "${Data_Path}" ]; then + check_z=$(ls "${Data_Path}") + if [[ ! -z "${check_z}" ]]; then + return + fi + fi + + mkdir -p ${Data_Path} + chown -R mysql:mysql ${Data_Path} + chgrp -R mysql ${Setup_Path}/. + + ${Setup_Path}/bin/mysqld --initialize-insecure --basedir=${Setup_Path} --datadir=${Data_Path} --user=mysql + + cat > /etc/ld.so.conf.d/mysql.conf<