当前位置:网站首页>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 $*
边栏推荐
- What are the models of data modeling
- Canoe cannot automatically identify serial port number? Then encapsulate a DLL so that it must work
- Safety notes
- Delayed note learning
- C杂讲 文件 续讲
- 五月刷题01——数组
- Which is the better prospect for mechanical engineer or Electrical Engineer?
- June brush question 02 - string
- [one click] it only takes 30s to build a blog with one click - QT graphical tool
- [CV] target detection: derivation of common terms and map evaluation indicators
猜你喜欢
Oom happened. Do you know the reason and how to solve it?
Combined search /dfs solution - leetcode daily question - number of 1020 enclaves
C杂讲 双向循环链表
【深度学习】语义分割:论文阅读(NeurIPS 2021)MaskFormer: per-pixel classification is not all you need
嵌入式开发比单片机要难很多?谈谈单片机和嵌入式开发设计经历
Several silly built-in functions about relative path / absolute path operation in CAPL script
I2C summary (single host and multi host)
MapReduce instance (VI): inverted index
手把手教您怎么编写第一个单片机程序
Nc17 longest palindrome substring
随机推荐
CANoe仿真功能之自动化序列(Automation Sequences )
Une grande vague d'attaques à la source ouverte
嵌入式開發中的防禦性C語言編程
学习单片机对社会的帮助是很大的
Control the operation of the test module through the panel in canoe (Advanced)
Delayed note learning
手把手教您怎么编写第一个单片机程序
Processes of libuv
大学C语言入门到底怎么学才可以走捷径
解决小文件处过多
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
[Chongqing Guangdong education] reference materials for nine lectures on the essence of Marxist Philosophy in Wuhan University
[untitled]
June brush question 02 - string
33岁可以学PLC吗
为什么大学单片机课上51+汇编,为什么不直接来STM32
112 pages of mathematical knowledge sorting! Machine learning - a review of fundamentals of mathematics pptx
Redis distributed lock implementation redison 15 questions
Nc29 search in two-dimensional array