|
|
|
@ -5,10 +5,71 @@
|
|
|
|
|
`export FLASK_ENV=development`
|
|
|
|
|
`flask run`
|
|
|
|
|
|
|
|
|
|
# in production
|
|
|
|
|
**Using gunicorn:**
|
|
|
|
|
|
|
|
|
|
`gunicorn -w 4 -b 127.0.0.1:5000 app:app`
|
|
|
|
|
* `-w` workers
|
|
|
|
|
* `-b` bind to address / unix socker
|
|
|
|
|
|
|
|
|
|
or using unix sock:
|
|
|
|
|
`gunicorn --workers 4 --bind unix:app.sock -m 007 wsgi:app `
|
|
|
|
|
**And gunicorn with using unix sock:** (this how it should run in production)
|
|
|
|
|
`gunicorn --workers 4 --bind unix:app.sock -m 007 app:app `
|
|
|
|
|
|
|
|
|
|
## in Production with gunicorn and unix sockets
|
|
|
|
|
Based on https://medium.com/faun/deploy-flask-app-with-nginx-using-gunicorn-7fda4f50066a
|
|
|
|
|
|
|
|
|
|
### systemd service file
|
|
|
|
|
|
|
|
|
|
Add to /etc/systemd/system/watermarks.service
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[Unit]
|
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
|
User=psc
|
|
|
|
|
Group=www-data
|
|
|
|
|
WorkingDirectory=/var/www/TacticalApp
|
|
|
|
|
Environment="PATH=/var/www/TacticalApp/venv/bin"
|
|
|
|
|
ExecStart=/var/www/TacticalApp/venv/bin/gunicorn --workers 4 --bind unix:app.sock -m 007 app:app
|
|
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## enable & start service file
|
|
|
|
|
`systemctl enable watermarks.service`
|
|
|
|
|
|
|
|
|
|
`systemctl start watermarks.service`
|
|
|
|
|
|
|
|
|
|
It is also a good idea to check the status of the service
|
|
|
|
|
`systemctl status watermarks.service`
|
|
|
|
|
|
|
|
|
|
## Nginx config
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
location / {
|
|
|
|
|
include proxy_params;
|
|
|
|
|
# it will pass the requests to the socket
|
|
|
|
|
proxy_pass http://unix:/var/www/TacticalApp/app.sock;
|
|
|
|
|
# @andre: unsure whether we need a proxy_redirect as well
|
|
|
|
|
# if so, it might be somthing like
|
|
|
|
|
# http://unix:/var/www/TacticalApp/app.sock $scheme://$host:80/;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## debug.
|
|
|
|
|
|
|
|
|
|
It might be helpful to enable gunicorn logging, while in development, to check what is going on,
|
|
|
|
|
by replacing in watermarks.service, the `ExecStart=` value with:
|
|
|
|
|
|
|
|
|
|
`ExecStart=/var/www/TacticalApp/venv/bin/gunicorn --log-level debug --error-logfile /var/www/TacticalApp/app.log --workers 4 --bind unix:app.sock -m 007 app:app`
|
|
|
|
|
|
|
|
|
|
And reloading the services
|
|
|
|
|
`systemctl daemon-reload`
|
|
|
|
|
|
|
|
|
|
`systemctl restart watermarks.service`
|
|
|
|
|
|
|
|
|
|
and the start following app.log:
|
|
|
|
|
`tail -f /var/www/TacticalApp/app.log`
|
|
|
|
|
|
|
|
|
|
But in the long run logging should be disabled
|