-
- #!/bin/bash
- ### BEGIN INIT INFO
- # Provides: yourautostart
- # Required-Start: $remote_fs
- # Required-Stop: $remote_fs
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: Auto Start Test
- # Descrption: This service is used to test auto start service
- ### END INIT INFO
-
- case "$1" in
- start):
- echo "Stat"
- nohup /usr/bin/python3 /home/pi/目录/XXXX.py &
- ;;
- stop):
- echo "Stop"
- #killall singlepic2baiduyun.py
- echo "Usage: service start_tool start|stop"
- exit 1
- ;;
- esac
- exit 0
1.新建一文件(无后缀),输入上述内容,修改xx为你的要启动的文件
需完整复制上面示列 ,否则产生错误,未定义启动等级
复制上面的文件到 /etc/init.d 下 ;使用命令 sudo cp xx/xx.py /etc/init.d/
2.程序执行 sudo chmod 777 xx.py
sudo update-rc.d yourautostart defaults //添加服务
sudo systemctl enable yourautostart //启动服务 命令已改变
/lib/systemd/systemd-sysv-install enable my_autostart
1,取消开机自动运行
sudo update-rc.d blinker remove
2. 关闭开机自启动
通过systemctl disable 来关闭开机自启动
sudo systemctl disable test.service
/lib/systemd/systemd-sysv-install disable my_autostart