leafsummer
8/4/2016 - 12:19 PM

uwsgi service command

uwsgi service command

#!/bin/sh
uwsgi=/usr/bin/uwsgi
apiconf=/opt/antapi/uwsgi.ini

case $1 in
    start)
        echo "Starting uwsgi"
        count=`ps -ef | grep 'uwsgi' | grep 'uwsgi.ini' | grep -v 'grep'`
        if [ ! -n "$count" ]; then
            $uwsgi -i $apiconf
            if [ $? -ne 0 ]; then
                echo "Failed to start"
            else
                echo "Started"
            fi
        else
            echo "uwsgi is running"
        fi
        ;;
    stop)
        echo "Stopping uwsgi"
        count=`ps -ef | grep 'uwsgi' | grep 'uwsgi.ini' | grep -v 'grep'`
        if [ -n "$count" ]; then
            if (ps aux | grep 'uwsgi' | grep 'uwsgi.ini' | grep -v 'grep' | awk '{ print $2 }' | xargs kill -9); then
                echo "Stopped"
            else
                echo "Failed to stop"
            fi
        else
            echo "uwsgi is not running"
        fi
        ;;
    restart|reload)
        echo "Restart uwsgi"
        sh ${0} stop
        sleep 2
        sh ${0} start
        ;;
    show)
        ps -ef | grep 'uwsgi' | grep 'uwsgi.ini' | grep -v 'grep'
        ;;
    *) 
        echo -n "Usage: $0 {start|stop|restart|reload|show}"
        ;;
esac