2 # -*- encoding: utf-8 -*-
3 ##############################################################################
5 # OpenERP, Open Source Management Solution
6 # Copyright (C) 2004-2008 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 #----------------------------------------------------------
37 import sys, os, signal
38 #----------------------------------------------------------
39 # ubuntu 8.04 has obsoleted `pyxml` package and installs here.
40 # the path needs to be updated before any `import xml`
41 # TODO: remove PyXML dependencies, use lxml instead.
42 #----------------------------------------------------------
43 _oldxml = '/usr/lib/python%s/site-packages/oldxml' % sys.version[:3]
44 if os.path.exists(_oldxml):
45 sys.path.append(_oldxml)
49 __author__ = release.author
50 __version__ = release.version
52 #----------------------------------------------------------
54 #----------------------------------------------------------
56 logger = netsvc.Logger()
58 #-----------------------------------------------------------------------
59 # import the tools module so that the commandline parameters are parsed
60 #-----------------------------------------------------------------------
63 logger.notifyChannel("server", netsvc.LOG_INFO, "version - %s" % release.version )
64 for name, value in [('addons_path', tools.config['addons_path']),
65 ('database hostname', tools.config['db_host'] or 'localhost'),
66 ('database port', tools.config['db_port'] or '5432'),
67 ('database user', tools.config['db_user'])]:
68 logger.notifyChannel("server", netsvc.LOG_INFO, "%s - %s" % ( name, value ))
72 if sys.platform == 'win32':
74 mx.DateTime.strptime = lambda x, y: mx.DateTime.mktime(time.strptime(x, y))
76 #----------------------------------------------------------
78 #----------------------------------------------------------
79 logger.notifyChannel("objects", netsvc.LOG_INFO, 'initialising distributed objects services')
81 dispatcher = netsvc.Dispatcher()
82 dispatcher.monitor(signal.SIGINT)
84 #---------------------------------------------------------------
85 # connect to the database and initialize it with base if needed
86 #---------------------------------------------------------------
89 #----------------------------------------------------------
90 # launch modules install/upgrade/removes if needed
91 #----------------------------------------------------------
92 if tools.config['upgrade']:
93 logger.notifyChannel('init', netsvc.LOG_INFO, 'Upgrading new modules...')
95 (toinit, toupdate) = tools.upgrade.upgrade()
97 tools.config['init'][m] = 1
99 tools.config['update'][m] = 1
101 #----------------------------------------------------------
102 # import basic modules
103 #----------------------------------------------------------
109 #----------------------------------------------------------
111 #----------------------------------------------------------
114 if tools.config['init'] or tools.config['update']:
115 pooler.get_db_and_pool(tools.config['db_name'], update_module=True)
117 #----------------------------------------------------------
119 #----------------------------------------------------------
120 if tools.config["translate_out"]:
123 if tools.config["language"]:
124 msg = "language %s" % (tools.config["language"],)
127 logger.notifyChannel("init", netsvc.LOG_INFO, 'writing translation file for %s to %s' % (msg, tools.config["translate_out"]))
129 fileformat = os.path.splitext(tools.config["translate_out"])[-1][1:].lower()
130 buf = file(tools.config["translate_out"], "w")
131 tools.trans_export(tools.config["language"], tools.config["translate_modules"], buf, fileformat)
134 logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written succesfully')
137 if tools.config["translate_in"]:
138 tools.trans_load(tools.config["db_name"], tools.config["translate_in"], tools.config["language"])
141 #----------------------------------------------------------------------------------
142 # if we don't want the server to continue to run after initialization, we quit here
143 #----------------------------------------------------------------------------------
144 if tools.config["stop_after_init"]:
148 #----------------------------------------------------------
150 #----------------------------------------------------------
152 if tools.config['xmlrpc']:
154 port = int(tools.config["port"])
156 logger.notifyChannel("init", netsvc.LOG_ERROR, "invalid port '%s'!" % (tools.config["port"],))
158 interface = tools.config["interface"]
159 secure = tools.config["secure"]
161 httpd = netsvc.HttpDaemon(interface, port, secure)
163 if tools.config["xmlrpc"]:
164 xml_gw = netsvc.xmlrpc.RpcGateway('web-services')
165 httpd.attach("/xmlrpc", xml_gw)
166 logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting XML-RPC%s services, port %s" % ((tools.config['secure'] and ' Secure' or ''), port))
169 #if tools.config["soap"]:
170 # soap_gw = netsvc.xmlrpc.RpcGateway('web-services')
171 # httpd.attach("/soap", soap_gw )
172 # logger.notifyChannel("web-services", netsvc.LOG_INFO, 'starting SOAP services, port '+str(port))
175 if tools.config['netrpc']:
177 netport = int(tools.config["netport"])
179 logger.notifyChannel("init", netsvc.LOG_ERROR, "invalid port '%s'!" % (tools.config["netport"],))
181 netinterface = tools.config["netinterface"]
183 tinySocket = netsvc.TinySocketServerThread(netinterface, netport, False)
184 logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting NET-RPC service, port "+str(netport))
187 def handler(signum, frame):
188 from tools import config
189 if tools.config['netrpc']:
191 if tools.config['xmlrpc']:
194 if config['pidfile']:
195 os.unlink(config['pidfile'])
198 from tools import config
199 if config['pidfile']:
200 fd = open(config['pidfile'], 'w')
201 pidtext = "%d" % (os.getpid())
205 signal.signal(signal.SIGINT, handler)
206 signal.signal(signal.SIGTERM, handler)
208 logger.notifyChannel("web-services", netsvc.LOG_INFO, 'the server is running, waiting for connections...')
209 if tools.config['netrpc']:
211 if tools.config['xmlrpc']:
218 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: