[IMP] extract method to reexec server

bzr revid: chs@openerp.com-20121123140838-pz47cw4jtlxx8e74
This commit is contained in:
Christophe Simonis 2012-11-23 15:08:38 +01:00
parent 246878558c
commit 927c5635b8
2 changed files with 16 additions and 10 deletions

View File

@ -210,12 +210,7 @@ def quit_on_signals():
if getattr(openerp, 'phoenix', False):
# like the phoenix, reborn from ashes...
strip_args = ['-d', '-u']
a = sys.argv[:]
args = [x for i, x in enumerate(a) if x not in strip_args and a[max(i - 1, 0)] not in strip_args]
# FIXME http socket cannot be rebind ?!? socket seems to not be freed, even shutdown() is called
os.execv(sys.executable, [sys.executable] + args)
openerp.service._reexec()
return
if config['pidfile']:

View File

@ -22,6 +22,7 @@
import logging
import os
import signal
import sys
import threading
import time
@ -126,15 +127,25 @@ def start_services_workers():
openerp.multi_process = True
openerp.service.workers.Multicorn(openerp.service.wsgi_server.application).run()
def _reexec():
"""reexecute openerp-server process with (nearly) the same arguments"""
strip_args = ['-d', '-u']
a = sys.argv[:]
args = [x for i, x in enumerate(a) if x not in strip_args and a[max(i - 1, 0)] not in strip_args]
os.execv(sys.executable, [sys.executable] + args)
def restart_server():
if openerp.multi_process:
raise NotImplementedError("Multicorn is not supported (but gunicorn was)")
pid = openerp.wsgi.core.arbiter_pid
os.kill(pid, signal.SIGHUP)
else:
openerp.phoenix = True
signame = 'CTRL_C_EVENT' if os.name == 'nt' else 'SIGINT'
sig = getattr(signal, signame)
os.kill(os.getpid(), sig)
if os.name == 'nt':
# TODO check if parent is a service
stop_services()
_reexec()
else:
openerp.phoenix = True
os.kill(os.getpid(), signal.SIGINT)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: