当前位置:网站首页>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 $*
边栏推荐
- MapReduce instance (VIII): Map end join
- Release of the sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
- 四川云教和双师模式
- 解决小文件处过多
- DCDC power ripple test
- 【深度学习】语义分割:论文阅读:(CVPR 2022) MPViT(CNN+Transformer):用于密集预测的多路径视觉Transformer
- PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
- 小白带你重游Spark生态圈!
- Cap theory
- C杂讲 浅拷贝 与 深拷贝
猜你喜欢

Defensive C language programming in embedded development
![[CV] target detection: derivation of common terms and map evaluation indicators](/img/e8/04cc8336223c0ab2dea5638def88df.jpg)
[CV] target detection: derivation of common terms and map evaluation indicators

C杂讲 动态链表操作 再讲

What are the models of data modeling
![[flask] crud addition and query operation of data](/img/fc/7a12ede31befed5f42b32b94ae5ecf.jpg)
[flask] crud addition and query operation of data
![[deep learning] semantic segmentation: paper reading: (CVPR 2022) mpvit (cnn+transformer): multipath visual transformer for dense prediction](/img/f1/6f22f00843072fa4ad83dc0ef2fad8.png)
[deep learning] semantic segmentation: paper reading: (CVPR 2022) mpvit (cnn+transformer): multipath visual transformer for dense prediction

【深度学习】语义分割-源代码汇总

CAPL 脚本对.ini 配置文件的高阶操作
[Yu Yue education] Wuhan University of science and technology securities investment reference

MapReduce instance (VI): inverted index
随机推荐
Tianmu MVC audit I
What are the models of data modeling
Popularization of security knowledge - twelve moves to protect mobile phones from network attacks
【深度學習】語義分割-源代碼匯總
解决小文件处过多
C杂讲 文件 初讲
五月刷题27——图
Can I learn PLC at the age of 33
Why can't TN-C use 2p circuit breaker?
CANoe仿真功能之自动化序列(Automation Sequences )
Keep these four requirements in mind when learning single chip microcomputer with zero foundation and avoid detours
Oom happened. Do you know the reason and how to solve it?
单片机如何从上电复位执行到main函数?
Inject common SQL statement collation
零基础学习单片机切记这四点要求,少走弯路
Hero League rotation chart manual rotation
CAPL脚本中关于相对路径/绝对路径操作的几个傻傻分不清的内置函数
四川云教和双师模式
Mapreduce实例(十):ChainMapReduce
为什么大学单片机课上51+汇编,为什么不直接来STM32