From f939c1e311af4819ab11f9a1f3e17f7d19afdbfc Mon Sep 17 00:00:00 2001 From: zj <1052308357@qq.comm> Date: Fri, 23 Jan 2026 05:30:10 +0800 Subject: [PATCH] fix23 --- tms-mysql.install | 95 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 25 deletions(-) diff --git a/tms-mysql.install b/tms-mysql.install index 44bbd0f..60d1391 100644 --- a/tms-mysql.install +++ b/tms-mysql.install @@ -87,34 +87,79 @@ post_remove() { echo "Reloading systemd daemon..." systemctl daemon-reload - # 如果是完全卸载 (即 $1 为 0),则清理用户、组和数据目录 - if [ "${remove_type}" -eq 0 ]; then - echo "Performing full uninstallation cleanup..." + echo "Performing full uninstallation cleanup..." - rm -rf /usr/local/mysql-5.6.47-linux-glibc2.12-x86_64 - rm -rf /usr/local/mysql + rm -rf /usr/local/mysql-5.6.47-linux-glibc2.12-x86_64 + rm -rf /usr/local/mysql - # 警告用户数据目录将被删除 - echo "WARNING: This will remove the MySQL data directory '${mysql_data_dir}' and all its data." - echo "Removing MySQL data directory '${mysql_data_dir}'..." - rm -rf "${mysql_data_dir}" - + # 警告用户数据目录将被删除 + echo "WARNING: This will remove the MySQL data directory '${mysql_data_dir}' and all its data." + echo "Removing MySQL data directory '${mysql_data_dir}'..." + rm -rf "${mysql_data_dir}" - # 删除用户和组 - if getent passwd "${mysql_user}" >/dev/null; then - echo "Removing user '${mysql_user}'..." - userdel "${mysql_user}" - fi - if getent group "${mysql_group}" >/dev/null; then - echo "Removing group '${mysql_group}'..." - groupdel "${mysql_group}" - fi - # 删除 PATH 环境变量配置脚本 - echo "Removing PATH configuration script '/etc/profile.d/mysql.sh'..." - rm -f /etc/profile.d/mysql.sh - echo "Full uninstallation cleanup complete." - else # remove_type is 1 (upgrade) - echo "MySQL package upgraded. Data directory and user/group are retained." + # 删除用户和组 + if getent passwd "${mysql_user}" >/dev/null; then + echo "Removing user '${mysql_user}'..." + userdel "${mysql_user}" fi + if getent group "${mysql_group}" >/dev/null; then + echo "Removing group '${mysql_group}'..." + groupdel "${mysql_group}" + fi + + # 删除 PATH 环境变量配置脚本 + echo "Removing PATH configuration script '/etc/profile.d/mysql.sh'..." + rm -f /etc/profile.d/mysql.sh + echo "Full uninstallation cleanup complete." + +} + + + +pre_upgrade() { + echo "Stopping MySQL service before removal..." + systemctl stop "${mysql_service}" + + # 警告用户数据目录将被删除 + echo "WARNING: This will remove the MySQL data directory '${mysql_data_dir}' and all its data." + echo "Removing MySQL data directory '${mysql_data_dir}'..." + rm -rf "${mysql_data_dir}" + + echo "Remove the MySQL data directory complete." +} + + +post_upgrade() { + + # 创建数据目录并设置权限 + if [ ! -d "${mysql_data_dir}" ]; then + echo "Creating MySQL data directory '${mysql_data_dir}'..." + mkdir -p "${mysql_data_dir}" + chown "${mysql_user}":"${mysql_group}" "${mysql_data_dir}" + chmod 0750 "${mysql_data_dir}" + fi + + local timeout=60 # 等待 MySQL 启动的超时时间 + + echo "Setting ownership for MySQL data directory '${mysql_data_dir}' to ${mysql_user}:${mysql_group}..." + chown -R "${mysql_user}":"${mysql_group}" "${mysql_data_dir}" + + echo "Starting MySQL service..." + systemctl start "${mysql_service}" + + echo "Waiting for MySQL server to start (up to ${timeout} seconds)..." + for i in $(seq 1 "${timeout}"); do + "${mysql_install_dir}/bin/mysqladmin" ping -h 127.0.0.1 -P 3306 &>/dev/null && break + sleep 1 + done + + if ! "${mysql_install_dir}/bin/mysqladmin" ping -h 127.0.0.1 -P 3306 &>/dev/null; then + echo "Warning: MySQL server did not start in time. Please check system logs for '${mysql_service}'." >&2 + # 不再强制退出,因为数据库已预初始化,服务启动失败可能是其他配置问题 + else + echo "MySQL server is running." + fi + + echo "SmartTMS MySQL installation/upgrade complete." }