当前位置:网站首页>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

边栏推荐
- AcWing 787. Merge sort (template)
- LeetCode 513. Find the value in the lower left corner of the tree
- Hudi 快速体验使用(含操作详细步骤及截图)
- Crawler career from scratch (3): crawl the photos of my little sister ③ (the website has been disabled)
- Instant messaging IM is the countercurrent of the progress of the times? See what jnpf says
- Flink学习笔记(十一)Table API 和 SQL
- The "booster" of traditional office mode, Building OA office system, was so simple!
- 2022-2-14 learning xiangniuke project - Session Management
- [set theory] order relation (chain | anti chain | chain and anti chain example | chain and anti chain theorem | chain and anti chain inference | good order relation)
- Computing level network notes
猜你喜欢
![[point cloud processing paper crazy reading classic version 12] - foldingnet: point cloud auto encoder via deep grid deformation](/img/62/edb888200e3743b03e5b39d94758f8.png)
[point cloud processing paper crazy reading classic version 12] - foldingnet: point cloud auto encoder via deep grid deformation

Crawler career from scratch (3): crawl the photos of my little sister ③ (the website has been disabled)

Introduction to the basic application and skills of QT

【点云处理之论文狂读前沿版11】—— Unsupervised Point Cloud Pre-training via Occlusion Completion

LeetCode 57. Insert interval

2022-2-14 learning xiangniuke project - Session Management

IDEA 中使用 Hudi

【点云处理之论文狂读经典版13】—— Adaptive Graph Convolutional Neural Networks
![[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

Instant messaging IM is the countercurrent of the progress of the times? See what jnpf says
随机推荐
The server denied password root remote connection access
[point cloud processing paper crazy reading classic version 10] - pointcnn: revolution on x-transformed points
PowerDesigner does not display table fields, only displays table names and references, which can be modified synchronously
CSDN markdown editor help document
[point cloud processing paper crazy reading frontier version 11] - unsupervised point cloud pre training via occlusion completion
LeetCode 324. Swing sort II
[untitled] use of cmake
LeetCode 508. The most frequent subtree elements and
[kotlin learning] control flow of higher-order functions -- lambda return statements and anonymous functions
Derivation of Fourier transform
AcWing 788. Number of pairs in reverse order
[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
Severity code description the project file line prohibits the display of status error c2440 "initialization": unable to convert from "const char [31]" to "char *"
CATIA automation object architecture - detailed explanation of application objects (I) document/settingcontrollers
Logstash+jdbc data synchronization +head display problems
Excel is not as good as jnpf form for 3 minutes in an hour. Leaders must praise it when making reports like this!
What are the stages of traditional enterprise digital transformation?
Flink-CDC实践(含实操步骤与截图)
AcWing 786. Number k
2022-2-14 learning the imitation Niuke project - send email