← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~credativ/ocb-server/7.0-no-workers-no-listen into lp:ocb-server

 

mistotebe has proposed merging lp:~credativ/ocb-server/7.0-no-workers-no-listen into lp:ocb-server.

Requested reviews:
  OpenERP Community Backports Team (ocb)

For more details, see:
https://code.launchpad.net/~credativ/ocb-server/7.0-no-workers-no-listen/+merge/217744

Do not bind sockets when starting with no workers
  
If wanting to run the OpenERP server split out to a cron worker and a main server, the cron worker daemon must not try to bind the server socket.
  
This commit lets an explicit --workers=0 mean that we still want to run multiprocess, but are not going to listen anywhere.

Rationale for raising directly against OCB:
The "openerp-server" script has been removed in favor of the "oe" script not long after 7 has been released, therefore I presume OpenERP would not be interested in integrating this into 7.0 maintenance.
-- 
https://code.launchpad.net/~credativ/ocb-server/7.0-no-workers-no-listen/+merge/217744
Your team OpenERP Community Backports Team is requested to review the proposed merge of lp:~credativ/ocb-server/7.0-no-workers-no-listen into lp:ocb-server.
=== modified file 'openerp/cli/server.py'
--- openerp/cli/server.py	2014-03-19 10:48:47 +0000
+++ openerp/cli/server.py	2014-04-30 11:22:26 +0000
@@ -252,7 +252,7 @@
         setup_pid_file()
         # Some module register themselves when they are loaded so we need the
         # services to be running before loading any registry.
-        if config['workers']:
+        if config['workers'] is not None:
             openerp.service.start_services_workers()
         else:
             openerp.service.start_services()

=== modified file 'openerp/service/workers.py'
--- openerp/service/workers.py	2014-04-10 09:36:29 +0000
+++ openerp/service/workers.py	2014-04-30 11:22:26 +0000
@@ -35,7 +35,7 @@
     def __init__(self, app):
         # config
         self.address = (config['xmlrpc_interface'] or '0.0.0.0', config['xmlrpc_port'])
-        self.population = config['workers']
+        self.population = config['workers'] or 0
         self.timeout = config['limit_time_real']
         self.limit_request = config['limit_request']
         # working vars
@@ -48,6 +48,7 @@
         self.workers = {}
         self.generation = 0
         self.queue = []
+        self.socket = None
 
     def pipe_new(self):
         pipe = os.pipe()
@@ -172,12 +173,13 @@
         signal.signal(signal.SIGINT, self.signal_handler)
         signal.signal(signal.SIGTERM, self.signal_handler)
         signal.signal(signal.SIGCHLD, self.signal_handler)
-        # listen to socket
-        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-        self.socket.setblocking(0)
-        self.socket.bind(self.address)
-        self.socket.listen(8*self.population)
+        if self.population:
+            # listen to socket
+            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+            self.socket.setblocking(0)
+            self.socket.bind(self.address)
+            self.socket.listen(8*self.population)
 
     def stop(self, graceful=True):
         if graceful:
@@ -192,7 +194,8 @@
             _logger.info("Stopping forcefully")
         for pid in self.workers.keys():
             self.worker_kill(pid, signal.SIGTERM)
-        self.socket.close()
+        if self.socket:
+            self.socket.close()
         openerp.cli.server.quit_signals_received = 1
 
     def run(self):
@@ -285,11 +288,12 @@
         _logger.info("Worker %s (%s) alive", self.__class__.__name__, self.pid)
         # Reseed the random number generator
         random.seed()
-        # Prevent fd inherientence close_on_exec
-        flags = fcntl.fcntl(self.multi.socket, fcntl.F_GETFD) | fcntl.FD_CLOEXEC
-        fcntl.fcntl(self.multi.socket, fcntl.F_SETFD, flags)
-        # reset blocking status
-        self.multi.socket.setblocking(0)
+        if self.multi.socket:
+            # Prevent fd inherientence close_on_exec
+            flags = fcntl.fcntl(self.multi.socket, fcntl.F_GETFD) | fcntl.FD_CLOEXEC
+            fcntl.fcntl(self.multi.socket, fcntl.F_SETFD, flags)
+            # reset blocking status
+            self.multi.socket.setblocking(0)
         signal.signal(signal.SIGINT, self.signal_handler)
         signal.signal(signal.SIGTERM, signal.SIG_DFL)
         signal.signal(signal.SIGCHLD, signal.SIG_DFL)

=== modified file 'openerp/tools/config.py'
--- openerp/tools/config.py	2013-11-25 10:38:42 +0000
+++ openerp/tools/config.py	2014-04-30 11:22:26 +0000
@@ -279,7 +279,7 @@
 
         group = optparse.OptionGroup(parser, "Multiprocessing options")
         # TODO sensible default for the three following limits.
-        group.add_option("--workers", dest="workers", my_default=0,
+        group.add_option("--workers", dest="workers", my_default=None,
                          help="Specify the number of workers, 0 disable prefork mode.",
                          type="int")
         group.add_option("--limit-memory-soft", dest="limit_memory_soft", my_default=640 * 1024 * 1024,


Follow ups