|
在树莓派上配置的,理论上其他Linux系统也是一样的
1、先创建service文件
sudo nano /etc/systemd/system/o2server.service
填入以下内容:
[Unit]
Description=o2server Service
After=network.target
[Service]
Type=simple
User=pi
Group=pi
Restart=on-failure
RestartSec=5s
ExecStart=/home/pi/o2server/start_raspi.sh
ExecStop=/home/pi/o2server/stop_raspi.sh
[Install]
WantedBy=multi-user.target
编辑完保存退出
注意:
User和Group根据你自己的系统修改,一般不建议用root;
start 和stop 启动脚本路径要写对
启用service:
sudo systemctl enable o2server.service
注意:
只有先启用service,才会开机自动启动;
由于启动过程较复杂,系统启动之后需要等待一段时间才能访问
手动启动service:
sudo systemctl start o2server
手动停止service:
sudo systemctl stop o2server
手动重新启动service:
sudo systemctl restart o2server
其他systemctl命令请自行百度
|
|