2 # -*- encoding: utf-8 -*-
3 ##############################################################################
5 # OpenERP, Open Source Management Solution
6 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ##############################################################################
26 OpenERP is an ERP+CRM program for small and medium businesses.
28 The whole source code is distributed under the terms of the
31 (c) 2003-TODAY, Fabien Pinckaers - Tiny sprl
34 #----------------------------------------------------------
36 #----------------------------------------------------------
42 __author__ = release.author
43 __version__ = release.version
45 #----------------------------------------------------------
47 #----------------------------------------------------------
49 logger = netsvc.Logger()
51 #-----------------------------------------------------------------------
52 # import the tools module so that the commandline parameters are parsed
53 #-----------------------------------------------------------------------
56 logger.notifyChannel("server", netsvc.LOG_INFO, "version - %s" % release.version )
57 for name, value in [('addons_path', tools.config['addons_path']),
58 ('database hostname', tools.config['db_host'] or 'localhost'),
59 ('database port', tools.config['db_port'] or '5432'),
60 ('database user', tools.config['db_user'])]:
61 logger.notifyChannel("server", netsvc.LOG_INFO, "%s - %s" % ( name, value ))
65 if sys.platform == 'win32':
67 mx.DateTime.strptime = lambda x, y: mx.DateTime.mktime(time.strptime(x, y))
69 #----------------------------------------------------------
71 #----------------------------------------------------------
72 logger.notifyChannel("objects", netsvc.LOG_INFO, 'initialising distributed objects services')
74 #---------------------------------------------------------------
75 # connect to the database and initialize it with base if needed
76 #---------------------------------------------------------------
79 #----------------------------------------------------------
80 # import basic modules
81 #----------------------------------------------------------
87 #----------------------------------------------------------
89 #----------------------------------------------------------
93 #----------------------------------------------------------
94 # Load and update databases if requested
95 #----------------------------------------------------------
97 if tools.config['db_name']:
98 for db in tools.config['db_name'].split(','):
99 pooler.get_db_and_pool(db, update_module=tools.config['init'] or tools.config['update'])
101 #----------------------------------------------------------
103 #----------------------------------------------------------
104 if tools.config["translate_out"]:
107 if tools.config["language"]:
108 msg = "language %s" % (tools.config["language"],)
111 logger.notifyChannel("init", netsvc.LOG_INFO,
112 'writing translation file for %s to %s' % (msg,
113 tools.config["translate_out"]))
115 fileformat = os.path.splitext(tools.config["translate_out"])[-1][1:].lower()
116 buf = file(tools.config["translate_out"], "w")
117 tools.trans_export(tools.config["language"], tools.config["translate_modules"], buf, fileformat)
120 logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written successfully')
123 if tools.config["translate_in"]:
124 tools.trans_load(tools.config["db_name"],
125 tools.config["translate_in"],
126 tools.config["language"])
129 #----------------------------------------------------------------------------------
130 # if we don't want the server to continue to run after initialization, we quit here
131 #----------------------------------------------------------------------------------
132 if tools.config["stop_after_init"]:
136 #----------------------------------------------------------
138 #----------------------------------------------------------
140 if tools.config['xmlrpc']:
141 port = int(tools.config['port'])
142 interface = tools.config["interface"]
143 secure = tools.config["secure"]
145 httpd = netsvc.HttpDaemon(interface, port, secure)
147 xml_gw = netsvc.xmlrpc.RpcGateway('web-services')
148 httpd.attach("/xmlrpc", xml_gw)
149 logger.notifyChannel("web-services", netsvc.LOG_INFO,
150 "starting XML-RPC%s services, port %s" %
151 ((tools.config['secure'] and ' Secure' or ''), port))
154 #if tools.config["soap"]:
155 # soap_gw = netsvc.xmlrpc.RpcGateway('web-services')
156 # httpd.attach("/soap", soap_gw )
157 # logger.notifyChannel("web-services", netsvc.LOG_INFO, 'starting SOAP services, port '+str(port))
160 if tools.config['netrpc']:
161 netport = int(tools.config['netport'])
162 netinterface = tools.config["netinterface"]
163 tinySocket = netsvc.TinySocketServerThread(netinterface, netport, False)
164 logger.notifyChannel("web-services", netsvc.LOG_INFO,
165 "starting NET-RPC service, port %d" % (netport,))
167 LST_SIGNALS = ['SIGINT', 'SIGTERM']
168 if os.name == 'posix':
169 LST_SIGNALS.extend(['SIGUSR1','SIGQUIT'])
173 [(getattr(signal, sign), sign) for sign in LST_SIGNALS]
176 def handler(signum, _):
178 :param signum: the signal number
181 if tools.config['netrpc']:
183 if tools.config['xmlrpc']:
186 if tools.config['pidfile']:
187 os.unlink(tools.config['pidfile'])
188 logger.notifyChannel('shutdown', netsvc.LOG_INFO,
189 "Shutdown Server! - %s" % ( SIGNALS[signum], ))
193 for signum in SIGNALS:
194 signal.signal(signum, handler)
196 if tools.config['pidfile']:
197 fd = open(tools.config['pidfile'], 'w')
198 pidtext = "%d" % (os.getpid())
202 logger.notifyChannel("web-services", netsvc.LOG_INFO,
203 'the server is running, waiting for connections...')
205 if tools.config['netrpc']:
207 if tools.config['xmlrpc']:
213 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: