From 1faa92266e8d78ebdfc42bd94d4ec95b9a9b12b5 Mon Sep 17 00:00:00 2001 From: Wang Defa Date: Wed, 21 Jan 2026 12:40:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20apt=20=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E5=90=8E=E6=9C=8D=E5=8A=A1=E9=9C=80=E8=A6=81=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E9=87=8D=E6=96=B0=E5=90=AF=E7=94=A8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 prerm 脚本,升级时只停止服务不禁用 - 修改 postinst 脚本,升级后自动重启已启用的服务 - 首次安装仍保持手动启用服务的行为 --- debian/postinst | 16 ++++++++++++---- debian/prerm | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/debian/postinst b/debian/postinst index 44b28d1..2dcaf56 100755 --- a/debian/postinst +++ b/debian/postinst @@ -24,7 +24,7 @@ chmod -R 750 /var/lib/mond # Create configuration file if it doesn't exist if [ ! -f /var/lib/mond/params.conf ]; then - cat > /var/lib/mond/params.conf << 'EOF' + cat > /var/lib/mond/params.conf << 'CONF' # Mond Configuration File # This file is automatically created during installation # Edit this file to customize your Mond daemon settings @@ -116,7 +116,7 @@ log-level=1 # log-file: 日志文件保存路径 log-file=/var/log/mond/mond.log -EOF +CONF chown mond:mond /var/lib/mond/params.conf chmod 640 /var/lib/mond/params.conf fi @@ -125,11 +125,19 @@ fi chown root:mond /opt/mond/mond chmod 755 /opt/mond/mond -# Reload systemd +# Reload systemd and handle service restart on upgrade if [ -d /run/systemd/system ]; then systemctl daemon-reload - # Note: Service is NOT auto-enabled or auto-started + # On upgrade: restart service if it was enabled + if [ "$1" = "configure" ] && [ -n "$2" ]; then + # $2 is the previously installed version (only set on upgrade) + if systemctl is-enabled --quiet mond.service 2>/dev/null; then + echo "Restarting mond service after upgrade..." + systemctl start mond.service || true + fi + fi + # Note: On fresh install, service is NOT auto-enabled or auto-started # Users should manually enable the service: # systemctl enable mond.service # systemctl start mond.service diff --git a/debian/prerm b/debian/prerm index ef25451..fa0289b 100755 --- a/debian/prerm +++ b/debian/prerm @@ -1,17 +1,36 @@ #!/bin/sh set -e -# Stop and disable service if running -if [ -d /run/systemd/system ]; then - if systemctl is-active --quiet mond.service; then - echo "Stopping mond service..." - systemctl stop mond.service - fi - - if systemctl is-enabled --quiet mond.service 2>/dev/null; then - echo "Disabling mond service..." - systemctl disable mond.service - fi -fi +case "$1" in + upgrade) + # 升级时只停止服务,保留 enabled 状态 + if [ -d /run/systemd/system ]; then + if systemctl is-active --quiet mond.service; then + echo "Stopping mond service for upgrade..." + systemctl stop mond.service + fi + fi + ;; + remove|deconfigure) + # 删除时停止并禁用服务 + if [ -d /run/systemd/system ]; then + if systemctl is-active --quiet mond.service; then + echo "Stopping mond service..." + systemctl stop mond.service + fi + if systemctl is-enabled --quiet mond.service 2>/dev/null; then + echo "Disabling mond service..." + systemctl disable mond.service + fi + fi + ;; + failed-upgrade) + # 升级失败时不做操作 + ;; + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac exit 0