django启动脚本

#!/bin/bash

# uwsgi的pid文件路径
uwsgi_pid_path="./uwsgi.pid"
# 如果uwsgi.pid文件不存在,则不作处理
if [ ! -f "$uwsgi_pid_path" ]
then
    echo "uwsgi.pid is not found, first start"
# 如果uwsgi.pid文件存在,则查询进程状态
else
    # 获取uwsgi服务pid号
    uwsgi_pid=`cat ${uwsgi_pid_path}`
    # 查询uwsgi服务状态
    ps -fe | grep ${uwsgi_pid} |grep -v grep > /dev/null
fi
# 获取命令行第一个参数
status=$1
# 如果是启动服务
if [[ ${status} = "start"]]
#if [ "${status}"x == "start"x]
then
    # 如果是第一次启动,没有uwsgi.pid文件,则直接启动
    if [ ! -f "$uwsgi_pid_path" ]
    then
        uwsgi --ini uwsgi.ini
        supervisorctl restart all
        echo "First start. Started successfully"
    # 如果服务未启动,则直接启动
    elif [ $? -ne 0 ]
    then
        uwsgi --ini uwsgi.ini
        supervisorctl restart all
        echo "Started successfully"
    # 如果服务已经启动,则输出信息
    else
        echo "project has started, please to use restart"
    fi
# 如果是重启服务
elif [[ ${status} = "restart" ]]
then
    # 如果是第一次启动,没有uwsgi.pid文件,则直接启动
    if [ ! -f "$uwsgi_pid_path" ]
    then
        uwsgi --ini uwsgi.ini
        supervisorctl restart all
        echo "First start. Restarted successfully"
    # 如果服务未启动,则直接启动
    elif [ $? -ne 0 ]
    then
        uwsgi --ini uwsgi.ini
        supervisorctl restart all
        echo "service has not started, not need stop, Started successfully"
    # 如果服务已经启动,则重启服务
    else
        uwsgi --reload uwsgi.pid
        supervisorctl restart all
        echo "Retarted successfully"
    fi
# 如果是停止服务
elif [[ ${status} = "stop" ]]
then
    # 如果是第一次启动,没有uwsgi.pid文件,则直接不作处理
    if [ ! -f "$uwsgi_pid_path" ]
    then
        echo "First start. not need stop"
    # 如果服务未启动,则直接输出信息
    elif [ $? -ne 0 ]
    then
        echo "service has not started, not need stop"
    # 如果服务已经启动,则停止服务
    else
        uwsgi --stop uwsgi.pid
        supervisorctl stop all
        echo "Stoped successfully"
    fi
# 参数说明
elif [[ ${status} = "-h" ]]
then
    echo "start: start service
stop: stop service
restart: restart service"
else
    echo "The parameter is incorrect ,or no parameter. Please enter parameter at end

start: start service
stop: stop service
restart: restart service"
fi
#!/bin/bash

# uwsgi的pid文件路径
uwsgi_pid_path="./uwsgi.pid"
# 如果uwsgi.pid文件不存在,则不作处理
if [ ! -f "$uwsgi_pid_path" ]
then
    echo "uwsgi.pid is not found, first start"
# 如果uwsgi.pid文件存在,则查询进程状态
else
    # 获取uwsgi服务pid号
    uwsgi_pid=`cat ${uwsgi_pid_path}`
    # 查询uwsgi服务状态
    get_result=`ps -fe | grep ${uwsgi_pid} |grep -v grep`
fi
# 获取命令行第一个参数
status=$1
# 如果是启动服务
if [[ ${status} = "start" ]]
#if [ "${status}"x == "start"x ]
then
    # 如果是第一次启动,没有uwsgi.pid文件,则直接启动
    if [ ! -f "$uwsgi_pid_path" ]
    then
        uwsgi --ini uwsgi.ini
        supervisorctl restart all
        echo "First start. Started successfully"
    # 判断是否为空,如果为空,则服务未启动,直接启动
    elif [[ -z v${get_result} ]]
    then
        uwsgi --ini uwsgi.ini
        supervisorctl restart all
        echo "Started successfully"
    # 如果服务已经启动,则输出信息
    else
        echo "project has started, please to use restart"
    fi
# 如果是重启服务
elif [[ ${status} = "restart" ]]
then
    # 如果是第一次启动,没有uwsgi.pid文件,则直接启动
    if [ ! -f "$uwsgi_pid_path" ]
    then
        uwsgi --ini uwsgi.ini
        supervisorctl restart all
        echo "First start. Restarted successfully"
    # 如果服务未启动,则直接启动
    elif [[ -z v${get_result} ]]
    then
        uwsgi --ini uwsgi.ini
        supervisorctl restart all
        echo "service has not started, not need stop, Started successfully"
    # 如果服务已经启动,则重启服务
    else
        uwsgi --reload uwsgi.pid
        supervisorctl restart all
        echo "Retarted successfully"
    fi
# 如果是停止服务
elif [[ ${status} = "stop" ]]
then
    # 如果是第一次启动,没有uwsgi.pid文件,则直接不作处理
    if [ ! -f "$uwsgi_pid_path" ]
    then
        echo "First start. not need stop"
    # 如果服务未启动,则直接输出信息
    elif [[ -z v${get_result} ]]
    then
        echo "service has not started, not need stop"
    # 如果服务已经启动,则停止服务
    else
        uwsgi --stop uwsgi.pid
        supervisorctl stop all
        echo "Stoped successfully"
    fi
# 参数说明
elif [[ ${status} = "-h" ]]
then
    echo "start: start service
stop: stop service
restart: restart service"
else
    echo "The parameter is incorrect ,or no parameter. Please enter parameter at end

start: start service
stop: stop service
restart: restart service"
fi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值