一、概述
工作中使用uwsgi时,每次需要进入到工作目录,去执行uwsgi相关命令,比较繁琐。这里整理了一个uwsgi重启脚本!
根据参考链接,修改了部分内容(定义了变量,修复了一些bug,增加了颜色输出)
#!/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
fi if [ $ = start ]
then
if [ `eval $PSID` -gt ]
then
content="uwsgi is running!"
echo -e "\033[32m $content \033[0m"
exit
else
$UWSGI $INI
content="Start uwsgi service [OK]"
echo -e "\033[32m $content \033[0m"
fi elif [ $ = stop ];then
if [ `eval $PSID` -gt ];then
killall - uwsgi
fi
content="Stop uwsgi service [OK]"
echo -e "\033[32m $content \033[0m"
elif [ $ = restart ];then
if [ `eval $PSID` -gt ];then
killall - 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个变量,即可使用。
效果如下:
文本参考链接: