用户实测报错:deploy/install.sh: line 173: sudo: command not found 本脚本已经强制要求 root 权限,用 sudo 降权到服务用户本就多余, 且部分服务器(尤其精简系统/容器)根本没有安装 sudo。 - 新增 as_service_user():runuser → setpriv → su 依次回退, 并在三者都不可用时给出明确错误 - 替换全部 sudo -u 调用(npm ci / npm install / npm run build / 迁移) - 新增 http_get() / http_ok():curl → wget → node fetch 依次回退, 健康检查不再强依赖 curl - 启动前检查 systemctl(本部署依赖 systemd),缺失时给出可操作提示 - 修正 install.sh / uninstall.sh 中所有「用 sudo 执行」的提示文案 实测(桩替换 runuser 验证分派与参数传递): 有 runuser:runuser -u opendance -- npm ci --omit=dev --loglevel=error 仅 su:正确回退到 su HTTP:curl 路径与 node fetch 回退路径返回一致
54 lines
2.2 KiB
Bash
Executable File
54 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# ============================================================
|
|
# OpenDance Studio Web 服务端 —— 卸载(Linux 原生站点)
|
|
#
|
|
# 默认**保留**上传文件与数据库数据;只有显式加 --purge 才删除程序目录与上传目录。
|
|
# 数据库从来不由本脚本管理,永不删除。
|
|
#
|
|
# 用法:
|
|
# bash deploy/uninstall.sh # 停服务、禁用站点,保留数据(需 root)
|
|
# bash deploy/uninstall.sh --purge # 同时删除程序目录与上传文件
|
|
# ============================================================
|
|
set -euo pipefail
|
|
|
|
APP_DIR="${APP_DIR:-/opt/opendance}"
|
|
STORAGE_DIR="${STORAGE_DIR:-/var/lib/opendance/storage}"
|
|
SERVICE_USER="${SERVICE_USER:-opendance}"
|
|
PURGE=0
|
|
[ "${1:-}" = "--purge" ] && PURGE=1
|
|
|
|
log() { printf '\033[1;34m[uninstall]\033[0m %s\n' "$*"; }
|
|
warn() { printf '\033[1;33m[warn]\033[0m %s\n' "$*"; }
|
|
die() { printf '\033[1;31m[error]\033[0m %s\n' "$*" >&2; exit 1; }
|
|
|
|
[ "$(id -u)" -eq 0 ] || die "需要 root 权限。请以 root 身份执行,例如:
|
|
su -c 'bash deploy/uninstall.sh' 或 sudo bash deploy/uninstall.sh"
|
|
|
|
log "停止并禁用 opendance-api 服务"
|
|
systemctl stop opendance-api 2>/dev/null || true
|
|
systemctl disable opendance-api 2>/dev/null || true
|
|
rm -f /etc/systemd/system/opendance-api.service
|
|
systemctl daemon-reload
|
|
|
|
if command -v nginx >/dev/null 2>&1; then
|
|
log "移除 nginx 站点"
|
|
rm -f /etc/nginx/sites-enabled/opendance.conf /etc/nginx/sites-available/opendance.conf /etc/nginx/conf.d/opendance.conf
|
|
nginx -t >/dev/null 2>&1 && (systemctl reload nginx 2>/dev/null || nginx -s reload) || warn "nginx 重载跳过"
|
|
fi
|
|
|
|
if [ "$PURGE" -eq 1 ]; then
|
|
warn "删除程序目录 $APP_DIR 与上传目录 $STORAGE_DIR"
|
|
rm -rf "$APP_DIR" "$STORAGE_DIR"
|
|
if id -u "$SERVICE_USER" >/dev/null 2>&1; then
|
|
userdel "$SERVICE_USER" 2>/dev/null || true
|
|
log "已删除系统用户 $SERVICE_USER"
|
|
fi
|
|
log "完成(数据库未做任何改动)"
|
|
else
|
|
log "完成。已保留:"
|
|
echo " 程序目录:$APP_DIR"
|
|
echo " 上传目录:$STORAGE_DIR"
|
|
echo " 如需一并删除(root 身份):bash deploy/uninstall.sh --purge"
|
|
fi
|
|
echo " 数据库:始终由部署方自行管理,本脚本不做任何改动"
|