Nano Pi开机自动执行脚本

关于Nano Pi开机执行脚本,网上有教程说在rc.local中添加sh脚本执行,试了好多次都没成功,

这里运用

systemd添加自定义系统服务设置自定义开机启动

这里比如,我要运行的开机启动程序为 acation.py

 此代码路径为

/home/fa/demo

其内容为,运行一个音频文件

 那么如何设置它,开机启动呢?

首先在

/etc/systemd/system/

  下,新建一个

acation.service 文件

  在里面输入,并保存一下内容

[Unit]
Description=acation
after=network.target
 
[Service]
ExecStart=/usr/bin/python -u /home/fa/demo/acation.py
WorkingDirectory=/home/fa/demo
StandardOutput=inherit
StandardOutput=inherit
Type=oneshot
User=root
 
[Install]
WantedBy=multi-user.target

然后

设置python脚本开机启动

sudo systemctl daemon-reload

这样启动该脚本用service 命令就可以

sudo service acation start#启动
sudo service acation stop#停止

最后设置开机启动就好了

sudo systemctl enable acation.service

禁止开机启动:

sudo systemctl disable acation.service

参考:https://www.embbnux.com/2015/04/12/raspberry_pi_setting_python_script_start_on_boot/

原文地址:https://www.cnblogs.com/fw-qql/p/15006651.html