189 条记录
16 私有链接
16 私有链接
您的程序运行命令:
/path-to-your/app --conf /path-to-your/app.conf
创建 Systemd 单元文件:
sudo vi /etc/systemd/system/your-app.service
内容如下:
[Unit]
Description=your-app service
After=network.target
[Service]
Type=simple
ExecStart=/path-to-your/app --conf /path-to-your/app.conf
WorkingDirectory=/path-to-your/
Restart=on-failure
RestartSec=5
User=root
[Install]
WantedBy=multi-user.target
重新加载 Systemd 配置
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
设置开机启动并启动服务
sudo systemctl enable your-app
sudo systemctl start your-app
sudo systemctl status your-app
常用命令
启动服务 sudo systemctl start your-app
停止服务 sudo systemctl stop your-app
重启服务 sudo systemctl restart your-app
查看状态 sudo systemctl status your-app
设置开机自启 sudo systemctl enable your-app
禁用开机自启 sudo systemctl disable your-app