当前位置:网站首页>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 $*
边栏推荐
- PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
- Basic concepts of libuv
- Several ways of MySQL database optimization (pen interview must ask)
- 《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
- Download address of canoe, download and activation of can demo 16, and appendix of all canoe software versions
- Mapreduce实例(九):Reduce端join
- Zsh configuration file
- [CV] target detection: derivation of common terms and map evaluation indicators
- May brush question 26 - concurrent search
- Tianmu MVC audit II
猜你喜欢

Mapreduce实例(十):ChainMapReduce

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

Contrôle de l'exécution du module d'essai par panneau dans Canoe (primaire)

Counter attack of noodles: redis asked 52 questions in a series, with detailed pictures and pictures. Now the interview is stable

Combined search /dfs solution - leetcode daily question - number of 1020 enclaves

在CANoe中通过Panel面板控制Test Module 运行(初级)

Mapreduce实例(四):自然排序
![《ASP.NET Core 6框架揭秘》样章发布[200页/5章]](/img/4f/5688c391dd19129d912a3557732047.jpg)
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]

MapReduce instance (IX): reduce end join

Hugo blog graphical writing tool -- QT practice
随机推荐
What are the models of data modeling
Contrôle de l'exécution du module d'essai par panneau dans Canoe (primaire)
PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
Bugku web guide
华南技术栈CNN+Bilstm+Attention
在CANoe中通過Panel面板控制Test Module 運行(初級)
MapReduce working mechanism
I2C summary (single host and multi host)
Day 5 of MySQL learning
Function description of shell command parser
Mapreduce实例(六):倒排索引
Safety notes
CAP理论
Elk project monitoring platform deployment + deployment of detailed use (II)
嵌入式开发比单片机要难很多?谈谈单片机和嵌入式开发设计经历
MapReduce instance (IX): reduce end join
Processes of libuv
五月刷题26——并查集
CAPL 脚本打印函数 write ,writeEx ,writeLineEx ,writeToLog ,writeToLogEx ,writeDbgLevel 你真的分的清楚什么情况下用哪个吗?
Vs All comments and uncomments