工做中使用uwsgi时,每次须要进入到工做目录,去执行uwsgi相关命令,比较繁琐。这里整理了一个uwsgi重启脚本!html
根据参考连接,修改了部份内容(定义了变量,修复了一些bug,增长了颜色输出)linux
#!/bin/bash INI="/www/mysite1/uwsgi/uwsgi.ini" UWSGI="/virtualenvs/venv/bin/uwsgi" PSID="ps aux | grep "uwsgi"| grep -v "grep" | wc -l" if [ ! -n "$1" ] then content="Usages: sh uwsgiserver.sh [start|stop|restart]" echo -e "\033[31m $content \033[0m" exit 0 fi if [ $1 = start ] then if [ `eval $PSID` -gt 4 ] then content="uwsgi is running!" echo -e "\033[32m $content \033[0m" exit 0 else $UWSGI $INI content="Start uwsgi service [OK]" echo -e "\033[32m $content \033[0m" fi elif [ $1 = stop ];then if [ `eval $PSID` -gt 4 ];then killall -9 uwsgi fi content="Stop uwsgi service [OK]" echo -e "\033[32m $content \033[0m" elif [ $1 = restart ];then if [ `eval $PSID` -gt 4 ];then killall -9 uwsgi fi $UWSGI --ini $INI content="Restart uwsgi service [OK]" echo -e "\033[32m $content \033[0m" else content="Usages: sh uwsgiserver.sh [start|stop|restart]" echo -e "\033[31m $content \033[0m" fi
注意:请根据实际状况,修改上面2个变量,便可使用。bash
效果以下:spa
文本参考连接:rest