【筆記】配置Python腳本自啓動服務

創建自啓動任務

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章