进入/etc/systemd/system/目录,创建myscript.service,并赋予权限
sudo vim /etc/systemd/system/myscript.service
[Unit]
Description=My Script Service
After=network.target
?
[Service]
User=root
ExecStart=/home/start.sh
Restart=always
?
[Install]
【其中User是开发板的用户名,米尔为root,
否则查看运行状态显示 myscript.service: Failed to determine user credentials: No such process
ExecStart是执行脚本,使用绝对路径表示】
输入一下指令:
sudo systemctl daemon-reload
?
sudo systemctl start myscript.service
?
sudo systemctl enable myscript.service
重启开发板后查看服务开启状态
sudo systemctl status myscript.service
关闭自启动服务
sudo systemctl stop myscript.service
?
sudo systemctl disable myscript.service