编写 Debian Service文件
2026/9/6小于 1 分钟
编写 xxx.service
$ vim /etc/systemd/system/xxx.service
[Unit]
Description=Your Service Description
[Service]
Type=simple
WorkingDirectory=/path/to/my/working/directory
ExecStart=/path/to/your/start_script.sh # 运行一个前台进程
ExecStop=/path/to/your/stop_script.sh # 可选
Restart=always
# Environment 指令方式确定环境变量
Environment="VAR1=value1"
Environment="VAR2=value2"
# EnvironmentFile 指令读取环境变量文件
EnvironmentFile=/path/to/your/environment_vars.env
# like:
k1=v1
k2=v2
[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload管理命令
sudo systemctl enable xxx
sudo systemctl start xxx
sudo systemctl stop xxx
sudo systemctl disable xxx
sudo systemctl status xxx