1

My goal:

-serve multiple python flask applications under the same development server

-no server side caching

-run gunicorn applications as background tasks

-nginx as reverse proxy that will resolve application instances by hostname, running all on port 80

I've realised I can run my Flask/Gunicorn application in a background using systemd - the problem is, it serves cached version of my application and I'd like to serve a new version of my build, everytime I commit new work into it while running

systemd/system/website.com.service

[Unit]
Description=Gunicorn instance to serve website.com
After=network.target

[Service]
User=melcma
Group=www-data
PIDFile=/var/tmp/gunicorn.pid
WorkingDirectory=/var/www/website.com
Environment="PATH=/var/www/website.com/env/bin"
ExecStart=/var/www/website.com/env/bin/gunicorn --workers 1 --bind unix:website.com.sock -m 007 wsgi:app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

From what I learned, this line: "ExecReload=/bin/kill -s HUP $MAINPID" is supposed to reload my server, but how do I trigger it under files change? I've tried to add "--reload" to ExecStart command but no effect.

And bonus question:

Is using systemd for this purpose a good way or it would rather butcher the server? (running task in background that launches gunicorn instance and refreshes itself under files changes)

  • I believe it is not good idea to reload it automatically. Its much better to call systemctl reload website.com explicitly. While guicorn supports --reload key (docs.gunicorn.org/en/19.0/settings.html#reload) it is not recommended from production. – user996142 Jul 4 '17 at 19:55
  • pardon me, I mean for development (local) server, that's why I need instant reload on files change. – Melcma Jul 4 '17 at 20:00
  • So why do you need systemd to run local server? I mean can't you run gunicorn directly? And even with systemd you could use --reload key – user996142 Jul 4 '17 at 20:14
  • Entire server would be a clone of production server, so it should serve multiple applications as they might communicate together. Running them with --reload would be a solution, but I don't really want to run multiple terminals every time. Any better solution? – Melcma Jul 4 '17 at 20:21
  • I've tried to run it like that in systemd, but that takes no effect: ExecStart=/var/www/website.com/env/bin/gunicorn --reload --workers 1 --bind unix:website.com.sock -m 007 wsgi:app – Melcma Jul 4 '17 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.