当前位置:网站首页>Flask+supervisor installation realizes background process resident
Flask+supervisor installation realizes background process resident
2022-07-03 09:24:00 【zeng31403】
Flask+Supervisor Install to realize background process resident
This time, we mainly try to run virtual machine Flask+Supervisor Background operation
Before flask demo Operation of , Only run when the task is started . In order to run in the background for a long time ,
You have to use Supervisor Only when the machine is switched on and off and the process is loaded and maintained can the local shutdown web page still be opened .
Steps are as follows :
- Open the created flask Environmental Science , newly build requirements.txt List all the flask Components
pip install -r requirements.txt Here is the content
Flask==0.10.1
Flask-Login==0.2.11
Flask-Mail==0.9.1
Flask-Moment==0.4.0
Flask-PageDown==0.1.5
Flask-SQLAlchemy==2.0
Flask-Script==2.0.5
Flask-WTF==0.10.2
Flask-Cache==0.13.1
Flask-Restless==0.15.0
Flask-Uploads==0.1.3
Jinja2==2.7.3
Mako==1.0.0
Markdown==2.5.1
MarkupSafe==0.23
SQLAlchemy==0.9.8
WTForms==2.0.1
Werkzeug==0.9.6
html5lib==1.0b3
itsdangerous==0.24
six==1.8.0
awesome-slugify==1.6
loading uwsgi / gunicorn
pip install uwsgi
pip install gunicornReturn to Flask Create... Under the project directory uwsgi.ini( This is to use uwsgi Of , however gunicorn Simpler, it seems )
[uwsgi]
# uwsgi The address and port used when starting
socket = 0.0.0.0:5000
# Internet access port , If you use it directly uWSGI Extranet , Because of the use of Nginx, Therefore, it is noted out
# http= :80
# The site directory points to
chdir = /root/projects/flask_car/
# python Start program file
wsgi-file = server.py
# python To start in a program application Variable name
# app yes manage.py A variable in a program file , The type of this variable is Flask Of application class
callable = app
# Number of processors
processes = 4
# Number of threads
threads = 2
# State detection address
stats = 0.0.0.0:9191
daemonize=/var/log/uwsgi.log
Run the command to install the configuration
uwsgi config.ini
install Supervisor
supervisor As a process guardian , To listen to web service , once web Hang up ,supervisor It will start itself . Make sure web The server will not be hung
(1) Out of the environment deactivate
(2) Install extended warehouse sudo yum install -y epel-release
(3) install yum install -y supervisor
(4) Check the installation position rpm -ql supervisor
(5) find /etc/superisord.conf
(6) Modify this file vim superisord.conf
mkdir /etc/supervisor
(7) By running echo_supervisord_conf Program generation supervisor Initialization profile for
echo_supervisord_conf > /etc/supervisor/supervisord.conf
(8) open /etc/supervisor/supervisord.conf The last line shows
It's under this directory ini Will load , Then in /etc/supervisor.d Add one below
;[include]
;files = relative/directory/*.ini
# Add the following
[include]
files = conf.d/*.conf
(9) Add a profile flask_car.conf To conf.d Under the table of contents
[program:flask_car]
# Start command entry
# command=flask/bin/uwsgi ./uwsgi.ini
command=flask/bin/gunicorn -w 4 -b 0.0.0.0:5000 server:app
# command=flask/bin/python3 ./server.py
# The directory where the command program is located
directory=/root/projects/flask_car/
# The command to run the user name
user=root
autostart=true
autorestart=true
# Log address
stdout_logfile=/root/projects/flask_car/logs/uwsgi_supervisor.log
priority=1
killasgroup=true
stopasgroup=true
(10) start-up supervisor
supervisord -c /etc/supervisor/supervisord.conf
(11) Check the startup
ps -ef | grep supervisord
(12) If the relevant process has been started, kill and restart
kill -s SIGTERM 31333 Kill the first process Here you can see the startup 
The port to take up Visible , If there is occupation, use kill The process number is ok
netstat -lntp # Check the port , If not, install net-tools Just input again
yum -y install net-tools
(13) To configure Supervisor Boot up
newly build ( Rewrite if it exists )/usr/lib/systemd/system/supervisord.service
```
# dservice for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
```
(14) Turn on and verify that it is turned on correctly
- Carry out orders
systemctl enable supervisord
- Or reload
systemctl daemon-reload
- Validation command
systemctl is-enabled supervisord

边栏推荐
- Vscode编辑器右键没有Open In Default Browser选项
- Pic16f648a-e/ss PIC16 8-bit microcontroller, 7KB (4kx14)
- Overview of database system
- AcWing 786. Number k
- 图像修复方法研究综述----论文笔记
- 【点云处理之论文狂读前沿版11】—— Unsupervised Point Cloud Pre-training via Occlusion Completion
- Problems in the implementation of lenet
- [point cloud processing paper crazy reading classic version 14] - dynamic graph CNN for learning on point clouds
- Idea uses the MVN command to package and report an error, which is not available
- Construction of simple database learning environment
猜你喜欢

NPM install installation dependency package error reporting solution
![[point cloud processing paper crazy reading classic version 14] - dynamic graph CNN for learning on point clouds](/img/7d/b66545284d6baea2763fd8d8555e1d.png)
[point cloud processing paper crazy reading classic version 14] - dynamic graph CNN for learning on point clouds

Hudi 快速体验使用(含操作详细步骤及截图)

State compression DP acwing 291 Mondrian's dream

Windows安装Redis详细步骤

Solve POM in idea Comment top line problem in XML file
![[point cloud processing paper crazy reading frontier version 11] - unsupervised point cloud pre training via occlusion completion](/img/76/b92fe4549cacba15c113993a07abb8.png)
[point cloud processing paper crazy reading frontier version 11] - unsupervised point cloud pre training via occlusion completion

LeetCode 871. Minimum refueling times

Spark 结构化流写入Hudi 实践

AcWing 786. Number k
随机推荐
[graduation season | advanced technology Er] another graduation season, I change my career as soon as I graduate, from animal science to programmer. Programmers have something to say in 10 years
【点云处理之论文狂读前沿版10】—— MVTN: Multi-View Transformation Network for 3D Shape Recognition
Utilisation de hudi dans idea
Jenkins learning (II) -- setting up Chinese
【点云处理之论文狂读前沿版11】—— Unsupervised Point Cloud Pre-training via Occlusion Completion
AcWing 785. Quick sort (template)
【点云处理之论文狂读前沿版12】—— Adaptive Graph Convolution for Point Cloud Analysis
npm install安装依赖包报错解决方法
Flink-CDC实践(含实操步骤与截图)
Hudi 数据管理和存储概述
【Kotlin学习】高阶函数的控制流——lambda的返回语句和匿名函数
LeetCode 438. Find all letter ectopic words in the string
Banner - Summary of closed group meeting
Beego learning - JWT realizes user login and registration
State compression DP acwing 291 Mondrian's dream
[kotlin learning] control flow of higher-order functions -- lambda return statements and anonymous functions
Construction of simple database learning environment
2022-2-14 learning xiangniuke project - generate verification code
The less successful implementation and lessons of RESNET
2022-2-14 learning xiangniuke project - Session Management