uwsgi重启shell脚本

一、概述

工作中使用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 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个变量,即可使用。

 

效果如下:

 

 

 

文本参考链接:

https://www.168seo.cn/linux/24874.html

 

posted @ 2019-09-18 20:25  肖祥  阅读(1248)  评论(0编辑  收藏  举报