/etc/init.d目录下的开机自启脚本
1.进入/etc/init.d/文件下
cd /etc/init.d/
2.创建test.sh文件
cat /etc/init.d/test.sh
3.修改test.sh里面的内容
#!/bin/bash
### BEGIN INIT INFO
# Provides: test.sh //test.sh是自己创建的脚本名称
# Required-Start: $local_fs $network $remote_fs $syslog
# Required-Stop: $local_fs $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the test.sh daemon //test.sh是自己创建的脚本名称
# Description: starts test.sh using start-stop-daemon //test.sh是自己创建的脚本名称
### END INIT INFO
/usr/bin/python3 /home/firefly/python/server.py //开机后需要执行的命令
4.赋权限给test.sh脚本文件
sudo chmod 755 /etc/init.d/test.sh
5.加入开机启动
sudo update-rc.d /etc/init.d/test.sh defaults 99 //在ubuntu环境认可的命令,如果出现,请进入到/etc/init.d目录执行update-rc.d的命令。
如果报错如下
update-rc.d: error: unable to read /etc/init.d//etc/init.d/test.sh
执行
cd /etc/init.d/
sudo update-rc.d /etc/init.d/test.sh defaults 99
6.判断test.sh是否能正常开机运行
cd /etc/init.d/
bash test.sh
修改报错,确保第6步能正常运行
7. 重启验证