当前位置:网站首页>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
边栏推荐
- [point cloud processing paper crazy reading classic version 8] - o-cnn: octree based revolutionary neural networks for 3D shape analysis
- LeetCode 241. Design priorities for operational expressions
- Detailed steps of windows installation redis
- We have a common name, XX Gong
- Serializer rewrite: update and create methods
- Jenkins learning (I) -- Jenkins installation
- 【点云处理之论文狂读经典版11】—— Mining Point Cloud Local Structures by Kernel Correlation and Graph Pooling
- 2022-2-14 learning xiangniuke project - Session Management
- [set theory] order relation (eight special elements in partial order relation | ① maximum element | ② minimum element | ③ maximum element | ④ minimum element | ⑤ upper bound | ⑥ lower bound | ⑦ minimu
- ERROR: certificate common name “*.” doesn’t match requested ho
猜你喜欢
MySQL installation and configuration (command line version)
Build a solo blog from scratch
The "booster" of traditional office mode, Building OA office system, was so simple!
[point cloud processing paper crazy reading frontier version 8] - pointview gcn: 3D shape classification with multi view point clouds
【点云处理之论文狂读前沿版9】—Advanced Feature Learning on Point Clouds using Multi-resolution Features and Learni
【Kotlin学习】高阶函数的控制流——lambda的返回语句和匿名函数
【毕业季|进击的技术er】又到一年毕业季,一毕业就转行,从动物科学到程序员,10年程序员有话说
dried food! What problems will the intelligent management of retail industry encounter? It is enough to understand this article
Excel is not as good as jnpf form for 3 minutes in an hour. Leaders must praise it when making reports like this!
Crawler career from scratch (II): crawl the photos of my little sister ② (the website has been disabled)
随机推荐
【点云处理之论文狂读经典版9】—— Pointwise Convolutional Neural Networks
[kotlin puzzle] what happens if you overload an arithmetic operator in the kotlin class and declare the operator as an extension function?
[kotlin learning] classes, objects and interfaces - define class inheritance structure
STM32F103 can learning record
Sword finger offer II 029 Sorted circular linked list
We have a common name, XX Gong
[point cloud processing paper crazy reading frontier version 11] - unsupervised point cloud pre training via occlusion completion
IDEA 中使用 Hudi
Bert install no package metadata was found for the 'sacraments' distribution
There is no open in default browser option in the right click of the vscade editor
Hudi 快速体验使用(含操作详细步骤及截图)
Banner - Summary of closed group meeting
Build a solo blog from scratch
Common formulas of probability theory
Common penetration test range
Crawler career from scratch (3): crawl the photos of my little sister ③ (the website has been disabled)
NPM install installation dependency package error reporting solution
Solve POM in idea Comment top line problem in XML file
[point cloud processing paper crazy reading frontier version 10] - mvtn: multi view transformation network for 3D shape recognition
【Kotlin学习】类、对象和接口——定义类继承结构