1. 程式人生 > >Linux入門:uwsgi自動化指令碼

Linux入門:uwsgi自動化指令碼

uwsgi預設情況下,啟動之後,只能使用kill進行關閉,為了使uwsgi的啟動關閉和linux中其它服務一樣,可以使用shell指令碼進行配置,指令碼如下:

vim testshell/uwsgiC.sh

#!/bin/bash
if [ ! -n "$1" ];then            #$1:指該指令碼後跟的第一個引數,-n:判斷$1是否為非空,!:取相反
    echo "Usages: sh uwsgiC.sh [start|stop|restart]"
    exit 0
fi

if [ $1 = start ];then            #如果第一個引數等於start,執行下面命令
psid = `ps aux | grep "uwsgi" | grep -v "grep" | wc -l` #上面執行了啟動之後,判斷啟動是否正常,grep -v過濾掉“grep”,使用wc -l檢視輸出幾行 if [$psid -gt 4];then echo "uwsgi is running!" exit 0 else /root/.pyenv/shims/uwsgi /usr/share/nginx/mysite/uwsgi.ini echo "Start uwsgi service [OK]"
fi elif [ $1 = stop ];then killall -9 uwsgi echo "Stop uwsgi service [OK]" elif [ $1 = restart ];then killall -9 uwsgi /root/.pyenv/shims/uwsgi /usr/share/nginx/mysite/uwsgi.ini echo "Restart uwsgi service [OK]" else echo "Usages: sh uwsgiC.sh [start|stop|restart]" fi

這裡寫圖片描述
配置uwsgi pid檔案

#uwsgi.ini  
……  
pidfile = /tmp/uwsgi.pid  
……  

關閉或重啟uwsgi

$ uwsgi --stop /tmp/uwsgi.pid
$ uwsgi --reload /tmp/uwsgi.pid