I have been running gunicorn to serve a Python Flask app using the commands
conda activate fooenv
gunicorn --workers=4 -b 0.0.0.0:5000 --worker-class=meinheld.gmeinheld.MeinheldWorker api.app:app
How can we use pm2 instead to run gunicorn/flask app inside the fooenv environment?
supposed you can run gunicorn in your venv via e.g.:
gunicorn wsgi:app -b localhost:5010
then you simply use command (in the venv):
pm2 --name=myapp start "gunicorn wsgi:app -b localhost:5010"
(took me way too long to figure this out btw)
I would create a pm2.json file in the same directory as your app, then start it with pm2 start pm2.json. pm2 ls will now show your app running.
{
"apps": [
{
"name": "my-app",
"script": "gunicorn --workers=4 -b 0.0.0.0:5000 --worker-class=meinheld.gmeinheld.MeinheldWorker api.app:app",
"watch": false,
"max_memory_restart": "256M",
"output": "/var/www/html/logs/my-app-out.log",
"error": "/var/www/html/logs/my-app-error.log",
"kill_timeout": 5000,
"restartDelay": 5000
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With