Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoreload with gunicorn? #50

Open
elioscordo opened this issue Sep 14, 2012 · 7 comments
Open

Autoreload with gunicorn? #50

elioscordo opened this issue Sep 14, 2012 · 7 comments

Comments

@elioscordo
Copy link

elioscordo commented Sep 14, 2012

Is there any chance to reload translation with gunicorn?
Something similar to ROSETTA_WSGI_AUTO_RELOAD and ROSETTA_UWSGI_AUTO_RELOAD.

@mbi
Copy link
Owner

mbi commented Nov 6, 2012

Hi.

Sorry for the delay, I also fling Django with gunicorn, so this would definitely be useful for me, too.

I think the cleanest way to accomplish generic reloading would be to simply add a setting that gets executed as a shell command, this could be e.g. "sudo supervisorctl restart myapp_gunicorn" or "touch myapp.wsgi" when running under mod_wsgi.

@bmihelac
Copy link
Contributor

bmihelac commented Nov 7, 2012

Hi all,

one way to approach this is through signals.

Currently rosetta trigger post_save signal and one could listen to this signal to reload gunicorn:
https://github.com/mbi/django-rosetta/blob/develop/rosetta/views.py#L149

Did not tried but I think this should work:

from django.dispatch import receiver
from rosetta.signals import post_save


@receiver(post_save)
def restart_server(sender, **kwargs):
    import os
    os.system("kill -HUP `cat /tmp/myproject.pid`")

I do like idea that command for reloading is read from settings as this would allow different settings for dev/prod environments.

Here is similar approach to trigger django dev server reloading:

from django.dispatch import receiver
from rosetta.signals import post_save


@receiver(post_save)
def restart_server(sender, **kwargs):
    import os
    os.system("sleep 1 && echo \"Rosetta reload\" && touch %s &" % __file__)

Note: running this process in background and sleeping for one second should give current rosetta view to redirect properly.

@olasfar
Copy link

olasfar commented Jan 29, 2017

+1 Do you know guys when this will be fixed ? Is there any workaround ? Thx

@DylanYoung
Copy link

I'm curious as I'm unfamiliar with the internals, but is the reload/restart necessary?

Would this snippet implemented as a post_save receiver (instead of middleware) accomplish the same?

@chitak
Copy link

chitak commented Jan 8, 2019

Not sure what is the status for this,
because I am using supervisor+gunicorn, so I modify slightly this snippet, and it works. I define this in my signals.py

@receiver(post_save)
def restart_server(sender, **kwargs):
    os.system('supervisorctl restart <myproject>')

@DylanYoung
Copy link

@chitak The problem with that is it will only work if your web application user has permission to use supervisorctl, which is not a particularly scalable or common setup, I think. If you want a more robust solution, try with the snippet I posted above.

@jepaulbadillos
Copy link

Any working workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants