#!/usr/bin/env bash


source activate pingpu

DIR_NAME=$(cd `dirname "$0"`; pwd)
SCRIPT_NAME="uwsgi.ini"
SCRIPT_FILE="${DIR_NAME}/${SCRIPT_NAME}"

function start_service() {
    echo "启动中请稍等"

    uwsgi --ini "${SCRIPT_FILE}"
    sleep 1

    local ret=$(ps axu | grep "${SCRIPT_FILE}" | grep -v grep | wc -l)
    if [[ ${ret} -gt 0 ]];then
        echo "服务启动成功"
    else
        echo -e "\033[31m 启动失败请检查 \033[0m"
    fi
}

function stop_service() {
    echo "停止服务中请稍等"
    ps axu | grep "${SCRIPT_FILE}" | grep -v grep | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1
    local ret=$(ps axu | grep "${SCRIPT_FILE}"| grep -v grep | wc -l)
    if [[ ${ret} -eq 0 ]];then
        echo "服务停止成功"
        start_service
    else
        echo -e "\033[31m 停止失败请检查 \033[0m"
    fi
}

stop_service


