- 输入命令
sudo /usr/lib/systemd
- 查看是否存在system目录。
system存在,不需要创建。
system不存在,输入命令创建:sudo mkdir /usr/lib/systemd/system
- 创建service 文件。
输入命令:sudo vim /usr/lib/systemd/system/testboot.service
在testboot.service中输入以下内容:并保存退出。
[Unit]
Description=testboot
[Service]
Type=oneshot
ExecStart=/home/pi/LaserUsbTool.sh
[Install]
WantedBy=multi-user.target
- 设置开机自动启动,输入以下命令。
sudo systemctl enable testboot.service
- 重新启动机器测试,是否设置成功。
注意:
以下命令,可以控制service的运行
sudo systemctl disable testboot.service
sudo systemctl start testboot.service
sudo systemctl restart testboot.service
sudo systemctl stop testboot.service
sudo systemctl status testboot.service