[IMP] tests: added a simple test case to create a database via XML-RPC.
[odoo/odoo.git] / openerp / service / __init__.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
19 #
20 ##############################################################################
21
22 import http_server
23 import netrpc_server
24 import web_services
25
26 #.apidoc title: RPC Services
27
28 """ Classes of this module implement the network protocols that the
29     OpenERP server uses to communicate with remote clients.
30
31     Some classes are mostly utilities, whose API need not be visible to
32     the average user/developer. Study them only if you are about to
33     implement an extension to the network protocols, or need to debug some
34     low-level behavior of the wire.
35 """
36
37 def start_services():
38     import openerp
39     http_server = openerp.service.http_server
40     netrpc_server = openerp.service.netrpc_server
41
42     # Instantiate local services (this is a legacy design).
43     openerp.osv.osv.start_object_proxy()
44     # Export (for RPC) services.
45     openerp.service.web_services.start_web_services()
46
47     # Initialize the HTTP stack.
48     http_server.init_servers()
49     http_server.init_xmlrpc()
50     http_server.init_static_http()
51     netrpc_server.init_servers()
52
53     # Start the main cron thread.
54     openerp.netsvc.start_agent()
55
56     # Start the top-level servers threads (normally HTTP, HTTPS, and NETRPC).
57     openerp.netsvc.Server.startAll()
58
59 def stop_services():
60     import openerp
61     import logging
62     import threading
63     import time
64     openerp.netsvc.Agent.quit()
65     openerp.netsvc.Server.quitAll()
66     config = openerp.tools.config
67     logger = logging.getLogger('server')
68     logger.info("Initiating shutdown")
69     logger.info("Hit CTRL-C again or send a second signal to force the shutdown.")
70     logging.shutdown()
71
72     # manually join() all threads before calling sys.exit() to allow a second signal
73     # to trigger _force_quit() in case some non-daemon threads won't exit cleanly.
74     # threading.Thread.join() should not mask signals (at least in python 2.5)
75     for thread in threading.enumerate():
76         if thread != threading.currentThread() and not thread.isDaemon():
77             while thread.isAlive():
78                 # need a busyloop here as thread.join() masks signals
79                 # and would present the forced shutdown
80                 thread.join(0.05)
81                 time.sleep(0.05)
82
83
84 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
85