# 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