X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=openerp%2Fservice%2F__init__.py;h=b4588629e7113157c08d1b1e498a7c8c234cfb1d;hb=b91d70a42d5a4d0fb88f7e2b0097fff87283c968;hp=b9ee98fcab091cef2c61b708419955e8d2adf52e;hpb=94393cc074c3536260104a5565aeef72e339c5ce;p=odoo%2Fodoo.git diff --git a/openerp/service/__init__.py b/openerp/service/__init__.py index b9ee98f..b458862 100644 --- a/openerp/service/__init__.py +++ b/openerp/service/__init__.py @@ -19,9 +19,19 @@ # ############################################################################## +import logging +import threading +import time + import http_server import netrpc_server import web_services +import websrv_lib + +import openerp.netsvc +import openerp.osv +import openerp.tools +import openerp.wsgi #.apidoc title: RPC Services @@ -34,5 +44,55 @@ import web_services low-level behavior of the wire. """ +def start_services(): + """ Start all services. + + Services include the different servers and cron threads. + + """ + # Instantiate local services (this is a legacy design). + openerp.osv.osv.start_object_proxy() + # Export (for RPC) services. + web_services.start_web_services() + + # Initialize the HTTP stack. + #http_server.init_servers() + #http_server.init_xmlrpc() + #http_server.init_static_http() + netrpc_server.init_servers() + + # Start the main cron thread. + openerp.netsvc.start_agent() + + # Start the top-level servers threads (normally HTTP, HTTPS, and NETRPC). + openerp.netsvc.Server.startAll() + + + # Start the WSGI server. + openerp.wsgi.start_server() + + +def stop_services(): + """ Stop all services. """ + openerp.netsvc.Agent.quit() + openerp.netsvc.Server.quitAll() + config = openerp.tools.config + logger = logging.getLogger('server') + logger.info("Initiating shutdown") + logger.info("Hit CTRL-C again or send a second signal to force the shutdown.") + logging.shutdown() + + # Manually join() all threads before calling sys.exit() to allow a second signal + # to trigger _force_quit() in case some non-daemon threads won't exit cleanly. + # threading.Thread.join() should not mask signals (at least in python 2.5). + for thread in threading.enumerate(): + if thread != threading.currentThread() and not thread.isDaemon(): + while thread.isAlive(): + # Need a busyloop here as thread.join() masks signals + # and would prevent the forced shutdown. + thread.join(0.05) + time.sleep(0.05) + + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: