创建.service
文件
cd /etc/systemd/system/
sudo nano myprogram.service
在.service
文件中输入以下内容:
[Unit]
Description=Your Program Description
After=network.target
[Service]
ExecStart=/path/for/program
User=yourusername
[Install]
WantedBy=multi-user.target
运行以下命令启用服务并启动它:
sudo systemctl enable myprogram.service
//启用服务
sudo systemctl disable myprogram.service //禁用服务
sudo systemctl start myprogram.service //开启服务
sudo systemctl stop myprogram.service
//停止服务
sudo systemctl restart myprogram.service
//重启服务
sudo systemctl status myprogram.service //查看服务状态
.service的后缀可以忽略。
Comments | NOTHING