uwsgi restart shell script

I. Overview

When used at work uwsgi, every time you need to enter the working directory, to perform uwsgi related commands more complicated. Here uwsgi restart put together a script!

The reference links, modifying the part (defining the variables, fixes some bug, increased color output)

#!/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

Note: the actual situation, modify the above two variables, you can use.

 

Results are as follows:

 

 

 

Text reference links:

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

 

Guess you like

Origin www.cnblogs.com/xiao987334176/p/11545117.html