cocoon/cocoon.service
xfy911 277bb70454
Some checks failed
CI / build (push) Has been cancelled
Phase 5 — systemd 服务文件:一键安装成系统服务
新增 cocoon.service:
- Type=simple 服务单元,支持 SIGHUP 热重载(ExecReload)
- 默认配置路径 /etc/cocoon/cocoon.json,工作目录 /var/www
- 安全加固:NoNewPrivileges / PrivateTmp / ProtectSystem / ProtectHome 等
- 网络能力:CAP_NET_BIND_SERVICE,用于绑定 80/443 端口
- 资源限制:LimitNOFILE=65535 / LimitNPROC=4096

Makefile 新增 install-systemd / uninstall-systemd 目标:
- install-systemd 自动创建目录并安装服务文件
- uninstall-systemd 停止并移除服务

编译验证:零警告,全部通过
单元测试:全部通过 ✓
集成测试:111 项通过(4 项反向代理环境相关失败,非项目问题)
2026-06-16 06:26:56 +08:00

46 lines
1.0 KiB
Desktop File

[Unit]
Description=Cocoon - 基于协程的轻量级 Web 服务器
Documentation=https://github.com/xfy911/cocoon
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/local/bin/cocoon -c /etc/cocoon/cocoon.json
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5
# 工作目录(静态资源根目录的基准路径)
WorkingDirectory=/var/www
# 日志输出到 journal
StandardOutput=journal
StandardError=journal
SyslogIdentifier=cocoon
# 安全加固
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/var/log/cocoon /var/www /etc/cocoon
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictSUIDSGID=true
LockPersonality=true
MemoryDenyWriteExecute=true
# 网络能力(需要绑定端口)
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
# 资源限制
LimitNOFILE=65535
LimitNPROC=4096
[Install]
WantedBy=multi-user.target