Linux 部署如何配置开机自启(systemd)?
一键脚本安装
通过官方一键脚本直接安装时,推荐让脚本生成与当前安装目录一致的 service:
./install.sh service install
常用管理命令:
./install.sh service status
./install.sh service restart
./install.sh service uninstall
该功能只适用于 Linux 直接安装。Docker 部署使用容器的 --restart=always 或 Compose 中的 restart: always,不需要再为 ZFile 创建 systemd 服务。
手工安装
手工解压安装包时,可以创建 /etc/systemd/system/zfile.service:
[Unit]
Description=ZFile File Manager
After=network.target
[Service]
Type=forking
User=root
WorkingDirectory=/root/zfile-pro
ExecStart=/root/zfile-pro/bin/start.sh
ExecStop=/root/zfile-pro/bin/stop.sh
Restart=on-failure
RestartSec=10
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
统一安装包默认安装目录为 /root/zfile-pro。如果使用非 root 用户安装,请把 User 和路径改成实际值。
使配置生效并启动:
systemctl daemon-reload
systemctl enable --now zfile
systemctl status zfile
修改 service 文件后需要再次执行 systemctl daemon-reload。