[MERGE] users and groups: new implementation of group fields on users form view
[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 logging
23 import threading
24 import time
25
26 import http_server
27 import netrpc_server
28 import web_services
29 import websrv_lib
30
31 import openerp.cron
32 import openerp.modules
33 import openerp.netsvc
34 import openerp.osv
35 import openerp.tools
36 import openerp.wsgi
37
38 #.apidoc title: RPC Services
39
40 """ Classes of this module implement the network protocols that the
41     OpenERP server uses to communicate with remote clients.
42
43     Some classes are mostly utilities, whose API need not be visible to
44     the average user/developer. Study them only if you are about to
45     implement an extension to the network protocols, or need to debug some
46     low-level behavior of the wire.
47 """
48
49 def start_services():
50     """ Start all services.
51
52     Services include the different servers and cron threads.
53
54     """
55     # Instantiate local services (this is a legacy design).
56     openerp.osv.osv.start_object_proxy()
57     # Export (for RPC) services.
58     web_services.start_web_services()
59
60     # Initialize the HTTP stack.
61     #http_server.init_servers()
62     #http_server.init_static_http()
63     netrpc_server.init_servers()
64
65     # Start the main cron thread.
66     openerp.cron.start_master_thread()
67
68     # Start the top-level servers threads (normally HTTP, HTTPS, and NETRPC).
69     openerp.netsvc.Server.startAll()
70
71     # Start the WSGI server.
72     openerp.wsgi.start_server()
73
74
75 def stop_services():
76     """ Stop all services. """
77     # stop scheduling new jobs; we will have to wait for the jobs to complete below
78     openerp.cron.cancel_all()
79
80     openerp.netsvc.Server.quitAll()
81     openerp.wsgi.stop_server()
82     config = openerp.tools.config
83     logger = logging.getLogger('server')
84     logger.info("Initiating shutdown")
85     logger.info("Hit CTRL-C again or send a second signal to force the shutdown.")
86     logging.shutdown()
87
88     # Manually join() all threads before calling sys.exit() to allow a second signal
89     # to trigger _force_quit() in case some non-daemon threads won't exit cleanly.
90     # threading.Thread.join() should not mask signals (at least in python 2.5).
91     for thread in threading.enumerate():
92         if thread != threading.currentThread() and not thread.isDaemon():
93             while thread.isAlive():
94                 # Need a busyloop here as thread.join() masks signals
95                 # and would prevent the forced shutdown.
96                 thread.join(0.05)
97                 time.sleep(0.05)
98
99     openerp.modules.registry.RegistryManager.delete_all()
100
101
102 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
103