2009-10-20 10:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2009-10-14 12:32:15 +00:00
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2008-06-16 07:24:04 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 12:32:15 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 12:32:15 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
##############################################################################
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2011-09-24 16:33:58 +00:00
|
|
|
import logging
|
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
|
2011-04-18 15:57:33 +00:00
|
|
|
import http_server
|
|
|
|
import netrpc_server
|
2006-12-07 13:41:40 +00:00
|
|
|
import web_services
|
2011-09-25 00:00:38 +00:00
|
|
|
import websrv_lib
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2011-09-24 16:33:58 +00:00
|
|
|
import openerp.netsvc
|
|
|
|
import openerp.osv
|
|
|
|
import openerp.tools
|
2011-09-25 00:00:38 +00:00
|
|
|
import openerp.wsgi
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2011-07-01 23:19:56 +00:00
|
|
|
#.apidoc title: RPC Services
|
|
|
|
|
|
|
|
""" Classes of this module implement the network protocols that the
|
|
|
|
OpenERP server uses to communicate with remote clients.
|
|
|
|
|
|
|
|
Some classes are mostly utilities, whose API need not be visible to
|
|
|
|
the average user/developer. Study them only if you are about to
|
|
|
|
implement an extension to the network protocols, or need to debug some
|
|
|
|
low-level behavior of the wire.
|
|
|
|
"""
|
2008-07-23 15:01:27 +00:00
|
|
|
|
2011-09-23 13:34:08 +00:00
|
|
|
def start_services():
|
2011-09-24 16:33:58 +00:00
|
|
|
""" Start all services.
|
|
|
|
|
|
|
|
Services include the different servers and cron threads.
|
2011-09-23 13:34:08 +00:00
|
|
|
|
2011-09-24 16:33:58 +00:00
|
|
|
"""
|
2011-09-23 13:34:08 +00:00
|
|
|
# Instantiate local services (this is a legacy design).
|
|
|
|
openerp.osv.osv.start_object_proxy()
|
|
|
|
# Export (for RPC) services.
|
2011-09-24 16:33:58 +00:00
|
|
|
web_services.start_web_services()
|
2011-09-23 13:34:08 +00:00
|
|
|
|
|
|
|
# Initialize the HTTP stack.
|
2011-09-25 00:00:38 +00:00
|
|
|
#http_server.init_servers()
|
|
|
|
#http_server.init_static_http()
|
2011-09-23 13:34:08 +00:00
|
|
|
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()
|
|
|
|
|
2011-09-25 00:00:38 +00:00
|
|
|
# Start the WSGI server.
|
|
|
|
openerp.wsgi.start_server()
|
|
|
|
|
|
|
|
|
2011-09-23 13:34:08 +00:00
|
|
|
def stop_services():
|
2011-09-24 16:33:58 +00:00
|
|
|
""" Stop all services. """
|
2011-09-23 13:34:08 +00:00
|
|
|
openerp.netsvc.Agent.quit()
|
|
|
|
openerp.netsvc.Server.quitAll()
|
2011-09-25 15:02:32 +00:00
|
|
|
openerp.wsgi.stop_server()
|
2011-09-23 13:34:08 +00:00
|
|
|
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()
|
|
|
|
|
2011-09-24 16:33:58 +00:00
|
|
|
# Manually join() all threads before calling sys.exit() to allow a second signal
|
2011-09-23 13:34:08 +00:00
|
|
|
# to trigger _force_quit() in case some non-daemon threads won't exit cleanly.
|
2011-09-24 16:33:58 +00:00
|
|
|
# threading.Thread.join() should not mask signals (at least in python 2.5).
|
2011-09-23 13:34:08 +00:00
|
|
|
for thread in threading.enumerate():
|
|
|
|
if thread != threading.currentThread() and not thread.isDaemon():
|
|
|
|
while thread.isAlive():
|
2011-09-24 16:33:58 +00:00
|
|
|
# Need a busyloop here as thread.join() masks signals
|
|
|
|
# and would prevent the forced shutdown.
|
2011-09-23 13:34:08 +00:00
|
|
|
thread.join(0.05)
|
|
|
|
time.sleep(0.05)
|
|
|
|
|
|
|
|
|
2008-07-23 15:01:27 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|