Add gunicorn
This commit is contained in:
		
							parent
							
								
									690b325884
								
							
						
					
					
						commit
						6a6b2e5205
					
				
					 2 changed files with 26 additions and 1 deletions
				
			
		
							
								
								
									
										26
									
								
								manage.py
									
										
									
									
									
								
							
							
						
						
									
										26
									
								
								manage.py
									
										
									
									
									
								
							|  | @ -1,7 +1,29 @@ | ||||||
| #!/usr/bin/env python | #!/usr/bin/env python | ||||||
| import os | import os | ||||||
| from app import create_app, db | from app import create_app, db | ||||||
| from flask.ext.script import Manager, Shell | from flask.ext.script import Manager, Shell, Command, Option | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | # http://stackoverflow.com/a/24606817 | ||||||
|  | class GunicornServer(Command): | ||||||
|  |     """Run the app within Gunicorn""" | ||||||
|  | 
 | ||||||
|  |     def get_options(self): | ||||||
|  |         from gunicorn.config import make_settings | ||||||
|  | 
 | ||||||
|  |         settings = make_settings() | ||||||
|  |         options = ( | ||||||
|  |             Option(*klass.cli, action=klass.action) | ||||||
|  |             for setting, klass in settings.iteritems() if klass.cli | ||||||
|  |         ) | ||||||
|  |         return options | ||||||
|  | 
 | ||||||
|  |     def run(self, *args, **kwargs): | ||||||
|  |         from gunicorn.app.wsgiapp import WSGIApplication | ||||||
|  | 
 | ||||||
|  |         app = WSGIApplication() | ||||||
|  |         app.app_uri = 'manage:app' | ||||||
|  |         return app.run() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| app = create_app(os.getenv('FLASK_CONFIG') or 'default') | app = create_app(os.getenv('FLASK_CONFIG') or 'default') | ||||||
|  | @ -24,6 +46,8 @@ def initdb(): | ||||||
|         );""" |         );""" | ||||||
|     _ = db.engine.execute(text(cmd)) |     _ = db.engine.execute(text(cmd)) | ||||||
| 
 | 
 | ||||||
|  | manager.add_command("gunicorn", GunicornServer()) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|     manager.run() |     manager.run() | ||||||
|  |  | ||||||
|  | @ -9,3 +9,4 @@ itsdangerous==0.24 | ||||||
| psycopg2==2.6.1 | psycopg2==2.6.1 | ||||||
| Flask-WTF==0.12 | Flask-WTF==0.12 | ||||||
| WTForms==2.0.2 | WTForms==2.0.2 | ||||||
|  | gunicorn==19.3.0 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Matthew Dillon
						Matthew Dillon