当前位置:网站首页>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
边栏推荐
- LeetCode 438. Find all letter ectopic words in the string
- Spark structured stream writing Hudi practice
- [point cloud processing paper crazy reading classic version 11] - mining point cloud local structures by kernel correlation and graph pooling
- Beego learning - Tencent cloud upload pictures
- The idea of compiling VBA Encyclopedia
- The "booster" of traditional office mode, Building OA office system, was so simple!
- IDEA 中使用 Hudi
- Crawler career from scratch (II): crawl the photos of my little sister ② (the website has been disabled)
- On February 14, 2022, learn the imitation Niuke project - develop the registration function
- 【点云处理之论文狂读经典版9】—— Pointwise Convolutional Neural Networks
猜你喜欢
[point cloud processing paper crazy reading frontier version 11] - unsupervised point cloud pre training via occlusion completion
Flink学习笔记(九)状态编程
图像修复方法研究综述----论文笔记
Crawler career from scratch (IV): climb the bullet curtain of station B through API
Flink-CDC实践(含实操步骤与截图)
Django operates Excel files through openpyxl to import data into the database in batches.
LeetCode 324. Swing sort II
dried food! What problems will the intelligent management of retail industry encounter? It is enough to understand this article
AcWing 786. Number k
AcWing 788. Number of pairs in reverse order
随机推荐
Introduction to the basic application and skills of QT
The server denied password root remote connection access
【点云处理之论文狂读经典版14】—— Dynamic Graph CNN for Learning on Point Clouds
Common formulas of probability theory
Flink学习笔记(十)Flink容错机制
Crawler career from scratch (IV): climb the bullet curtain of station B through API
Move anaconda, pycharm and jupyter notebook to mobile hard disk
LeetCode 75. Color classification
[point cloud processing paper crazy reading classic version 8] - o-cnn: octree based revolutionary neural networks for 3D shape analysis
Temper cattle ranking problem
Crawler career from scratch (I): crawl the photos of my little sister ① (the website has been disabled)
LeetCode 871. Minimum refueling times
Sword finger offer II 091 Paint the house
Jenkins learning (II) -- setting up Chinese
Severity code description the project file line prohibits the display of status error c2440 "initialization": unable to convert from "const char [31]" to "char *"
Database execution error: SQL_ mode only_ full_ group_ by:
Build a solo blog from scratch
LeetCode 535. Encryption and decryption of tinyurl
LeetCode 438. Find all letter ectopic words in the string
Excel is not as good as jnpf form for 3 minutes in an hour. Leaders must praise it when making reports like this!