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