创建自启动任务
cd /etc/init.d/
sudo touch pymodel
sudo chmod +755 pymodel
sudo vim pymodel
编辑启动脚本
#!/bin/bash
### BEGIN INIT INFO
# Provides: pymodel
# Required-Start:
# Required-Stop:
# default-Start: 2 3 4 5
# default-Stop: 0 1 6
# Short-Description: Start/Stop pymodel server
### END INIT INFO
do_start()
{
cd /home/pi/pymodel/
nohup sudo python index.py 8000 &
}
do_stop()
{
ps -ef | grep index.py | awk '{print $2}' | xargs kill -9
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart)
do_stop
do_start
;;
*)
;;
esac
开启自动启动服务
apt-get install chkconfig -y
sudo chkconfing wechat on
chkconfing pymodel