编程文汇

debian/ubuntu把任意脚本包装成系统服务

debian
ubuntu
#1
  1. 准备好脚本,脚本本身可以是阻塞的,这时,在运行时,系统能检测得到
  2. 编写服务文件:
sudo vim /etc/systemd/system/frpc.service

[Unit]
After=network.target
ConditionPathExists=/home/zhmt/mydisk/study/prog/frp/run.sh

[Service]
User=zhmt
Type=simple
Restart=on-failure
ExecStartPre=/bin/sleep 5
ExecStart=/home/zhmt/mydisk/study/prog/frp/run.sh

[Install]
WantedBy=multi-user.target
  1. 自启动服务
sudo systemctl enable frpc.service
sudo systemctl start frpc.service
0 Likes