使用 systemd 管理服务(推荐)

创建 systemd 服务文件

服务文件 1:sudo nano /etc/systemd/system/sing-box-8585.service
[Unit]
Description=sing-box 8585 Service
After=network.target

[Service]
ExecStart=/usr/local/bin/sing-box run -c /etc/sing-box/8585.json
Restart=on-failure
User=nobody
Group=nogroup

[Install]
WantedBy=multi-user.target
服务文件 2:sudo nano /etc/systemd/system/sing-box-1080.service
[Unit]
Description=sing-box 1080 Service
After=network.target

[Service]
ExecStart=/usr/local/bin/sing-box run -c /etc/sing-box/1080.json
Restart=on-failure
User=nobody
Group=nogroup

[Install]
WantedBy=multi-user.target

启用并启动服务

bash

# 重新加载 systemd 配置
sudo systemctl daemon-reload

# 启用服务
sudo systemctl enable sing-box-8585
sudo systemctl enable sing-box-1080

# 启动服务
sudo systemctl start sing-box-8585
sudo systemctl start sing-box-1080

检查服务状态

sudo systemctl status sing-box-8585
sudo systemctl status sing-box-1080

停止服务

sudo systemctl stop sing-box-8585
sudo systemctl stop sing-box-1080

禁用服务

sudo systemctl disable sing-box-8585
sudo systemctl disable sing-box-1080