Created
January 31, 2012 10:39
-
-
Save mitchellrj/1709829 to your computer and use it in GitHub Desktop.
Patch PasteScript to support safe termination of daemon threads
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
[buildout] | |
eggs = ... | |
parts = ... | |
pastescript | |
[pastescript] | |
recipe = zc.recipe.egg | |
eggs = PasteScript # required to generate the specific paster script if not already in eggs list | |
${buildout:eggs} | |
extra-paths = path/to/pastescriptpatches.py | |
scripts = paster | |
initialization = import pastescriptpatches |
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
import os | |
import time | |
from paste.script.serve import live_pidfile | |
from paste.script.serve import read_pidfile | |
def patched_stop_daemon(self): | |
pid_file = self.options.pid_file or 'paster.pid' | |
if not os.path.exists(pid_file): | |
print 'No PID file exists in %s' % pid_file | |
return 1 | |
pid = read_pidfile(pid_file) | |
if not pid: | |
print "Not a valid PID file in %s" % pid_file | |
return 1 | |
pid = live_pidfile(pid_file) | |
if not pid: | |
print "PID in %s is not valid (deleting)" % pid_file | |
try: | |
os.unlink(pid_file) | |
except (OSError, IOError), e: | |
print "Could not delete: %s" % e | |
return 2 | |
return 1 | |
for j in range(10): | |
if not live_pidfile(pid_file): | |
break | |
import signal | |
os.kill(pid, signal.SIGINT) | |
time.sleep(1) | |
for j in range(10): | |
if not live_pidfile(pid_file): | |
break | |
import signal | |
os.kill(pid, signal.SIGTERM) | |
time.sleep(1) | |
else: | |
print "failed to kill web process %s" % pid | |
return 3 | |
if os.path.exists(pid_file): | |
os.unlink(pid_file) | |
return 0 | |
from paste.script.serve import ServeCommand | |
ServeCommand.stop_daemon__old__ = ServeCommand.stop_daemon | |
ServeCommand.stop_daemon = patched_stop_daemon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment