Skip to content

Instantly share code, notes, and snippets.

@cmorisse
Last active November 13, 2018 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmorisse/77f89871cce5f5a5d7611d583cc78f74 to your computer and use it in GitHub Desktop.
Save cmorisse/77f89871cce5f5a5d7611d583cc78f74 to your computer and use it in GitHub Desktop.
Odoo 12 _rexec() monkey patch for anybox.recipe.buildout compatibilty
import os
import sys
import logging
from odoo.service import server
from odoo.tools import misc
"""
Import this file from one loaded Odoo addon.
Update line 20 with path to odoo launcher.
"""
_logger = logging.getLogger('_reexec_patcher')
def patched_reexec(updated_modules=None):
"""reexecute openerp-server process with (nearly) the same arguments"""
args = misc.stripped_sys_argv()
if updated_modules:
args += ["-u", ','.join(updated_modules)]
buildout_launcher = "/home/cmorisse/environment/appserver-lk/bin/start_openerp"
# bin/start_openerp launches "odoo-bin -c file.cfg" so we removes
if args and args[0].endswith('odoo-bin'):
del args[0]
if args and args[0] == '-c':
del args[0:2]
# now we insert bin/start_openerp
if not args or (args and args[0] != buildout_launcher):
args.insert(0, buildout_launcher)
_logger.debug("buildout_launcher=%s", buildout_launcher)
_logger.debug("args=%s", args)
# We should keep the LISTEN_* environment variabled in order to support socket activation on reexec
#os.execve(sys.executable, args, os.environ)
os.execve(
buildout_launcher,
args,
os.environ
)
_logger.critical("Monkey patching server.py _reexec()")
server._reexec = patched_reexec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment