当前位置:网站首页>flask运维脚本(长时间运行)
flask运维脚本(长时间运行)
2022-07-06 09:05:00 【东方】
flask项目每次开启完总会自动关闭了。
听闻远方哥(QQ25008793)给我手写了一个脚本。。。。牛逼的一批。。
后台运行并且Shell退出程序依然运行使用命令:
nohup app.py & 在实际过程中,我们一般用脚本,另外就是用 docker k8s 自动编排。
给你写一个脚本。
脚本上传到这个目录就可以使用了,方式
sh ./start.sh start
start.sh代码如下:
function start(){
if [ ! -d 'venv' ]; then
python3 -m venv venv
fi
source venv/bin/activate
# requirements.txt
if [ ! -e 'requirements.txt' ]; then
echo 'error: "requirements.txt" file not found!'
exit
fi
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
nohup python app.py & echo $! > app.pid
echo "run app.py pid:$(cat app.pid)"
}
function stop() {
if [ -e 'app.pid' ]; then
pid=$(cat app.pid)
rm -rf 'app.pid'
for line in $(ps -ef|grep python|awk '{print $2}')
do
if [ $pid = $line ]; then
echo "kill: $pid"
kill $pid
fi
done
fi
}
function status() {
if [ -e 'app.id' ]; then
pid=$(cat 'app.id')
for line in $(ps -ef|grep python|awk '{print $2}')
do
if [ $pid = $line ]; then
echo "app.py ok $pid"
fi
done
fi
}
function main(){
command=$1
case command in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
status
;;
*)
echo '--------------------------命令列表--------------------------'
echo '| start 启动 |'
echo '| stop 停止 |'
echo '| restart 重启 |'
echo '| status 状态 |'
echo '-----------------------------------------------------------'
;;
}
# --------------------------
main $*
边栏推荐
- 硬件工程师的真实前途我说出来可能你们不信
- CANoe仿真功能之自动化序列(Automation Sequences )
- Nc17 longest palindrome substring
- Random notes
- Keep these four requirements in mind when learning single chip microcomputer with zero foundation and avoid detours
- 嵌入式中的合作开发--函数指针
- What you have to know about network IO model
- MapReduce instance (IX): reduce end join
- May brush question 26 - concurrent search
- 112 pages of mathematical knowledge sorting! Machine learning - a review of fundamentals of mathematics pptx
猜你喜欢

112 pages of mathematical knowledge sorting! Machine learning - a review of fundamentals of mathematics pptx

Selection of software load balancing and hardware load balancing

Single chip microcomputer realizes modular programming: Thinking + example + system tutorial (the degree of practicality is appalling)

MapReduce instance (IX): reduce end join

Hugo blog graphical writing tool -- QT practice

Segmentation sémantique de l'apprentissage profond - résumé du code source

Nc29 search in two-dimensional array

CANoe仿真功能之自动化序列(Automation Sequences )

Programmation défensive en langage C dans le développement intégré

学习单片机对社会的帮助是很大的
随机推荐
Mapreduce实例(四):自然排序
tn-c为何不可用2p断路器?
Mapreduce实例(六):倒排索引
美疾控中心:美国李斯特菌疫情暴发与冰激凌产品有关
CANoe仿真功能之自动化序列(Automation Sequences )
硬件工程师的真实前途我说出来可能你们不信
Cooperative development in embedded -- function pointer
美新泽西州州长签署七项提高枪支安全的法案
Why is 51+ assembly in college SCM class? Why not come directly to STM32
Nc29 search in two-dimensional array
听哥一句劝,按这套嵌入式的课程内容和课程体系去学习
单片机实现模块化编程:思维+实例+系统教程(实用程度令人发指)
五月刷题01——数组
CAPL 脚本对.ini 配置文件的高阶操作
Counter attack of noodles: redis asked 52 questions in a series, with detailed pictures and pictures. Now the interview is stable
Contrôle de l'exécution du module d'essai par panneau dans Canoe (primaire)
The replay block of canoe still needs to be combined with CAPL script to make it clear
Selection of software load balancing and hardware load balancing
Hard core! One configuration center for 8 classes!
Interview shock 62: what are the precautions for group by?