linux系统下django项目启动的shell脚本run.sh
脚本实例
#!/bin/bash
pid=$(ps -ef | grep “/root/memeplatform/ENV/bin/python meme/manage.py runserver” | grep -v “grep” | awk ‘{print $2}’)
notice(){
echo “用法:$0 {start|stop|restart}”
}
start() {
sleep 2
pids=$(ps -ef | grep “/root/memeplatform/ENV/bin/python meme/manage.py runserver” | grep -v “grep” | awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') if [ -n …{pids}" ]
then
echo “程序已经运行”
else
source /root/memeplatform/ENV/bin/activate
nohup /root/memeplatform/ENV/bin/python meme/manage.py runserver 0.0.0.0:8000 >/dev/null 2>&1 &
a=$?
sleep 3
if [ ${a} -eq 0 ]
then
echo “程序启动成功”
else
echo “程序启动失败”
fi
deactivate
fi
exit
}
stop() {
if [ -n “${pid}” ]
then
kill ${pid}
if [ $? -eq 0 ]
then
echo “程序已停止”
else
kill -9 ${pid}
if [ $? -eq 0 ]
then
echo “程序已停止”
else
echo “程序停止失败”
fi
fi
else
echo “程序没有运行”
fi
}
restart() {
stop
start
}
if [ $# -eq 1 ];then
case $1 in
“start”)

本文详细解析了一个用于Linux系统下启动Django项目的shell脚本run.sh,包括notice、start、stop和restart四个关键函数。脚本通过检查进程、启动服务、停止服务等操作实现项目的启动、停止和重启。同时,介绍了如何根据输入参数调用相应功能,为Django项目的自动化管理提供便利。
最低0.47元/天 解锁文章
3996

被折叠的 条评论
为什么被折叠?



