Commit 697f1cd4 authored by Łukasz Nowak's avatar Łukasz Nowak

- do singal translation for cloudooo, as paster is not killing children

   on SIGTERM, but on SIGINT only


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43965 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 50b7b8e6
...@@ -316,9 +316,9 @@ class Recipe(BaseSlapRecipe): ...@@ -316,9 +316,9 @@ class Recipe(BaseSlapRecipe):
conversion_server_dict)) conversion_server_dict))
self.path_list.append(config_file) self.path_list.append(config_file)
self.path_list.extend(zc.buildout.easy_install.scripts([(name, self.path_list.extend(zc.buildout.easy_install.scripts([(name,
__name__ + '.execute', 'execute')], self.ws, sys.executable, __name__ + '.execute', 'execute_with_signal_translation')], self.ws,
self.wrapper_directory, arguments=[self.options['ooo_paster'].strip(), sys.executable, self.wrapper_directory,
'serve', config_file])) arguments=[self.options['ooo_paster'].strip(), 'serve', config_file]))
self.connection_dict.update(**{ self.connection_dict.update(**{
name + '_port': conversion_server_dict['port'], name + '_port': conversion_server_dict['port'],
name + '_ip': conversion_server_dict['ip'] name + '_ip': conversion_server_dict['ip']
......
import sys
import os import os
import signal
import subprocess
import time
def execute(args): def execute(args):
"""Portable execution with process replacement""" """Portable execution with process replacement"""
# Note: Candidate for slapos.lib.recipe # Note: Candidate for slapos.lib.recipe
os.execv(args[0], args) os.execv(args[0], args)
child_pg = None
def sig_handler(signal, frame):
print 'Received signal %r, killing children and exiting' % signal
if child_pg is not None:
os.killpg(child_pg, signal.SIGHUP)
os.killpg(child_pg, signal.SIGTERM)
sys.exit(0)
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGQUIT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
def execute_with_signal_translation(args):
"""Run process as children and translate from SIGTERM to another signal"""
child = subprocess.Popen(args, close_fds=True, preexec_fn=os.setsid)
child_pg = child.pid
try:
while True:
print 'Running'
time.sleep(10)
finally:
os.killpg(child_pg, signal.SIGHUP)
os.killpg(child_pg, signal.SIGTERM)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment