ccraise 发表于 2022-11-17 10:24:48

分享一个Linux平台自启动配置,使用systemd方式

在树莓派上配置的,理论上其他Linux系统也是一样的

1、先创建service文件
sudo nano /etc/systemd/system/o2server.service
填入以下内容:



Description=o2server Service
After=network.target


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


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命令请自行百度





论坛管理员 发表于 2022-11-17 17:33:36

:handshake:handshake:handshake:handshake
非常感谢您的分享
页: [1]
查看完整版本: 分享一个Linux平台自启动配置,使用systemd方式