printServer/scripts/systemd/printserver.service
liufumingren fe23af7a7d chore(ops): 9.101 printServer 改为 systemd 托管
- 新增 printserver.service:开机自启(enabled)、崩溃自动拉起(Restart=always/RestartSec=5)、StartLimitBurst 防抖

- ExecStartPre 调用 release-orphan-running.cjs,启动前幂等释放断电/崩溃遗留的 running 任务

- KillMode=control-group:只连带本项目 frpc(/opt/printserver/frpc.ini),不影响系统 frpc.service

- 日志改 append(重启不丢),配 logrotate(daily + maxsize 200M / rotate 5 / copytruncate / 压缩)
2026-10-31 00:27:32 +08:00

44 lines
1.7 KiB
Desktop File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# printServer 录制客户端(9.101 / Linux)
#
# 进程关系(务必别搞混两套 frpc):
# 1) 本服务 = node index.js,它会自己 spawn 本项目的 frpc:
# /usr/local/bin/frpc -c /opt/printserver/frpc.ini
# 该子进程与本服务在同一个 cgroup 内,stop/restart 时一起退出,
# start 时由应用重新拉起(services/frpc.js)。
# 2) 系统自带的 frpc = 独立单元 frpc.service:
# /www/server/frpc/frpc -c /www/server/frpc/frpc.ini (宝塔/Gitea 用)
# 属于别的 cgroup,本服务任何操作都不会影响它。
#
# 安装:
# cp printserver.service /etc/systemd/system/printserver.service
# systemctl daemon-reload
# systemctl enable --now printserver
[Unit]
Description=printServer Recording Client (node index.js)
After=network-online.target
Wants=network-online.target
# 防止异常时疯狂重启(5 分钟内最多 10 次)
StartLimitIntervalSec=300
StartLimitBurst=10
[Service]
Type=simple
WorkingDirectory=/opt/printserver
# 启动前释放断电/崩溃遗留的 running 任务(幂等,失败不阻塞启动)
ExecStartPre=-/usr/bin/node /opt/printserver/scripts/release-orphan-running.cjs
ExecStart=/usr/bin/node /opt/printserver/index.js
# 崩溃/被 kill 后自动拉起
Restart=always
RestartSec=5
# 停服时给 node 和它 spawn 的本项目 frpc 都发 SIGTERM(system frpc 在别的 cgroup,不受影响)
KillMode=control-group
KillSignal=SIGTERM
TimeoutStopSec=20
# append 而不是 truncate:重启不丢日志;体积由 /etc/logrotate.d/printserver 控制
StandardOutput=append:/opt/printserver/run.log
StandardError=append:/opt/printserver/run.log
[Install]
WantedBy=multi-user.target