fix(deploy): 支持无 systemd 的环境,并修复降级路径的两个真实缺陷
用户实测:服务器没有 systemctl,install.sh 直接报错退出。
原错误信息本身也是错的(建议 SKIP_NGINX=1,但那只跳过 nginx,仍走 systemctl)。
进程管理改为四层降级:
systemd → OpenRC → SysVinit → nohup 后台进程(deploy/ctl.sh)
- 新增 deploy/ctl.sh:start/stop/restart/status/logs,PID 文件 + 进程名双重判定
- 新增 deploy/openrc/opendance-api、deploy/initd/opendance-api
- 无 init 系统时写 crontab @reboot 实现开机自启
- uninstall.sh 同步支持四种模式清理(原先只处理 systemd,会留下运行中的进程)
- 汇总输出按实际初始化系统给出对应运维命令
测试中发现并修复降级路径的两个真实缺陷:
1. nohup 无法调用 shell 函数
实测退出码 127 且什么都不执行
(nohup 是外部命令,只能执行可执行文件)。
这会让无 systemd 的降级路径完全失效——服务根本起不来。
改为按 runuser / setpriv / su 显式拼接成外部命令后再 nohup。
另加启动后 1 秒存活检测,失败立即打印日志,不再白等 30 秒。
2. find_pids 在无进程时返回一个空格
在空输入下仍会执行一次 echo,输出空行,
最终得到 " ";调用方 [ -n ... ] 会判为「有进程」,
导致 start 直接跳过、status 谎报运行中。改为纯 bash 拼接,空时返回空串。
实测(真实 API 进程,端口 3100):
start → 健康检查 200,PID 正确
重复 start → 识别已在运行,进程数保持 1
status → 运行中
restart → 新 PID,健康检查 200
stop → 无残留进程,端口释放
无 process 时 find_pids 返回空串,is_running=false
This commit is contained in:
+21
-6
@@ -16,9 +16,11 @@ OpenDance Studio —— Web 管理服务端 v0.1.0 使用说明
|
||||
Node 进程由 systemd 托管,只监听 127.0.0.1,外部只能经 nginx 访问。
|
||||
|
||||
前置要求
|
||||
- Linux 服务器(Debian/Ubuntu 或 RHEL 系均可),有 root 权限
|
||||
- Linux 服务器,有 root 权限(不需要 sudo,直接以 root 执行即可)
|
||||
- Node.js 22 或更高版本
|
||||
- nginx(未安装时脚本会跳过站点配置并给出提示)
|
||||
- 进程管理:systemd / OpenRC / SysVinit 均可;**三者都没有也能装**
|
||||
(自动降级为 nohup 后台进程 + PID 文件 + crontab @reboot 开机自启)
|
||||
- 一个可连通的现有 MySQL / MariaDB 实例,并已创建数据库与账号:
|
||||
|
||||
CREATE DATABASE IF NOT EXISTS dpendance
|
||||
@@ -67,11 +69,24 @@ Node 进程由 systemd 托管,只监听 127.0.0.1,外部只能经 nginx 访
|
||||
|
||||
数据库始终由部署方自行管理,卸载脚本不做任何改动。
|
||||
|
||||
常用命令
|
||||
systemctl status opendance-api # 服务状态
|
||||
journalctl -u opendance-api -f # 实时日志
|
||||
systemctl restart opendance-api # 重启
|
||||
nginx -t && systemctl reload nginx # 校验并重载 nginx
|
||||
常用命令(按安装时自动检测到的初始化系统而定)
|
||||
systemd:
|
||||
systemctl status opendance-api # 服务状态
|
||||
journalctl -u opendance-api -f # 实时日志
|
||||
systemctl restart opendance-api # 重启
|
||||
|
||||
OpenRC:
|
||||
rc-service opendance-api status / restart
|
||||
tail -f /var/log/opendance-api.log
|
||||
|
||||
SysVinit:
|
||||
/etc/init.d/opendance-api status / restart
|
||||
|
||||
无 init 系统(降级模式):
|
||||
bash /opt/opendance/deploy/ctl.sh status | restart | logs
|
||||
|
||||
nginx 配置校验:
|
||||
nginx -t && (systemctl reload nginx || rc-service nginx reload || nginx -s reload)
|
||||
|
||||
----------------------------------------------------------------
|
||||
二、本地开发
|
||||
|
||||
Reference in New Issue
Block a user