Created
January 19, 2010 00:32
-
-
Save vinilios/280537 to your computer and use it in GitHub Desktop.
uwsgi update on code change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os, sys, subprocess | |
from pyinotify import * | |
# the watch manager stores the watches and provide operations on watches | |
wm = WatchManager() | |
# watched events | |
mask = IN_DELETE | IN_CREATE | IN_MODIFY | |
class DirChanged(ProcessEvent): | |
uwsgi_process = 'uwsgi26' | |
def uwsgi_graceful_restart(self): | |
print "updating uwsgi..." | |
retcode = subprocess.call(["killall","-SIGHUP","uwsgi26"]) | |
print retcode | |
def process_IN_CREATE(self, event): | |
print "CREATED: " + event.path + "/" + event.name | |
self.uwsgi_graceful_restart() | |
def process_IN_DELETE(self, event): | |
print "DELETED: " + event.path + "/" + event.name | |
self.uwsgi_graceful_restart() | |
def process_IN_MODIFY(self, event): | |
print "MODIFIED: " + event.path + "/" + event.name | |
self.uwsgi_graceful_restart() | |
print "watching %s for changes" % os.path.abspath(sys.argv[1]) | |
wdd = wm.add_watch(os.path.abspath(sys.argv[1]), mask, rec=True) | |
notifier = Notifier(wm, DirChanged()) | |
while True: # loop forever | |
try: | |
# process the queue of events as explained above | |
notifier.process_events() | |
if notifier.check_events(): | |
# read notified events and enqeue them | |
notifier.read_events() | |
# you can do some tasks here... | |
except KeyboardInterrupt: | |
# destroy the inotify's instance on this interrupt (stop monitoring) | |
notifier.stop() | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment