linux 后台启动或重启django的脚本
#!/bin/bash
pid=`ps -ef|grep python3|grep manage|awk '{print $2}'`
echo $pid
if [[ ! $pid ]]
then
echo "#####Django服务未启动,现在启动#####"
cd /opt/workspace/
echo "#####Django启动服务#####"
nohup python3 manage.py runserver 0.0.0.0:PORT &
pid=`ps -ef|grep python3|grep manage|awk '{print $2}'`
if [[ ! $pid ]]
then
echo "#####Django服务启动失败#####"
else
echo "#####Django服务启动成功#####"
fi
else
echo "######关闭服务######"
kill $pid
pid=`ps -ef|grep python3|grep manage|awk '{print $2}'`
if [[ ! $pid ]]
then
echo "#####Django服务成功关闭#####"
cd /opt/workspace/
echo "#####Django启动服务#####"
nohup python3 manage.py runserver 0.0.0.0:PORT &
pid=`ps -ef|grep python3|grep manage|awk '{print $2}'|wc -l`
echo $pid
if [[ ! $pid ]]
then
echo "#####Django服务启动失败#####"
else
echo "#####Django服务启动成功#####"
fi
fi
fi