flask deploy the project to a production environment program

background

Written using Python + a small flask project, after completion of the development of local, need to be deployed to the test server, screenwriters this time, because before this thing is not deployed, so a variety of Baidu, finally successful deployment, and also this project was carried out jenkins continuous deployment, this after a time I would say it alone
 

The three parties involved in library

1 pip install gunicorn

 

supervisor profile

Since I installed the server pagoda panel, so use the pagoda inside the supervisor plug-in to manage the process, involving the need to add a supervisor profile here posted about my configuration
. 1 [Program: xxx- Server] Project Title #
 2 Command = / usr / local / to python3 / bin / gunicorn - C gun.py Manage: App # front gunicorn absolute path, the latter is gunicorn profile gun.py , manage your flask project Initiation document name
 3 Directory = / the WWW / xxx- Server # flask project storage path
 4 autorestart is = to true 
5 stdout_logfile = / the WWW / Server / log / mock- server.out.log log #
 6 redirect_stderr is = to true 
. 7 User = the root
 . 8 priority = 999

 

gun.py file

The above mentioned gun.py this profile, I posted the following about my profile
 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 # @Time    : 2019/11/19 14:24
 4 # @Author  : Weiqiang.long
 5 # @Site    :
 6 # @File    : gun.py
 7 # @Software: PyCharm
 8 # @Description:
 9 # import requests
10 import os
11 import platform
12 import gevent.monkey
13 import multiprocessing
14 
15 
16 gevent.monkey.patch_all ()
 . 17 Debug = True
 18 is LogLevel = ' deubg ' 
. 19  # service address (adderes: Port) 
20 is the bind = ' 0.0.0.0:8090 ' 
21 is  
22 is  
23 is  IF platform.system () == ' the Windows ' :
 24      # win machine path 
25      log_path, the os.path.join = (os.path.dirname ( __FILE__ ), ' log ' )
 26 is  the else :
 27      # server path 
28      log_path, = '/ log ' 
29  
30  
31 is  # Print (log_path,) 
32 PidFile = log_path, + ' /gunicorn.pid ' 
33 is logfile = log_path, + ' /debug.log ' 
34 is  
35  
36  # cores cpu number of processes started (acquired server 2 * + 1'd) 
37 [ Workers = multiprocessing.cpu_count () * 2 + 1'd
 38 is worker_class = ' gunicorn.workers.ggevent.GeventWorker ' 
39  
40  
41 is Threads = 20 is
 42 is preload_app = True
 43 is reload = True
 44 is  
45  
46 is x_forwarded_for_header = 'X-FORWARDED-FOR'

 

Start project supervisor

1  # start all services
 2  the sudo supervisorctl All Start
 . 3  
. 4  
. 5  # Start a single service
 . 6  the sudo supervisorctl Start service name
 . 7  
. 8  
. 9  # discontinue all
 10  the sudo supervisorctl All STOP
 . 11  
12 is  
13 is  # Reset all the services
 14  the sudo supervisorctl the restart All

 

 

Reference Source:

 

 

Guess you like

Origin www.cnblogs.com/longweiqiang/p/12053443.html