2 # -*- coding: utf-8 -*-
3 ##############################################################################
5 # OpenERP, Open Source Management Solution
6 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
25 OpenERP is an ERP+CRM program for small and medium businesses.
27 The whole source code is distributed under the terms of the
30 (c) 2003-TODAY, Fabien Pinckaers - Tiny sprl
33 #----------------------------------------------------------
35 #----------------------------------------------------------
40 #----------------------------------------------------------
41 # ubuntu 8.04 has obsoleted `pyxml` package and installs here.
42 # the path needs to be updated before any `import xml`
43 # TODO: remove PyXML dependencies, use lxml instead.
44 #----------------------------------------------------------
45 _oldxml1 = '/usr/lib/python%s/site-packages/oldxml' % sys.version[:3]
46 _oldxml2 = '/usr/lib/python%s/dist-packages/oldxml' % sys.version[:3]
47 if os.path.exists(_oldxml1):
48 sys.path.insert(0,_oldxml1)
49 elif os.path.exists(_oldxml2):
50 sys.path.insert(0,_oldxml2)
53 __author__ = release.author
54 __version__ = release.version
56 # We DON't log this using the standard logger, because we might mess
57 # with the logfile's permissions. Just do a quick exit here.
58 if pwd.getpwuid(os.getuid())[0] == 'root' :
59 sys.stderr.write("Attempted to run OpenERP server as root. This is not good, aborting.\n")
62 #----------------------------------------------------------
64 #----------------------------------------------------------
66 logger = netsvc.Logger()
68 #-----------------------------------------------------------------------
69 # import the tools module so that the commandline parameters are parsed
70 #-----------------------------------------------------------------------
73 logger.notifyChannel("server", netsvc.LOG_INFO, "version - %s" % release.version )
74 for name, value in [('addons_path', tools.config['addons_path']),
75 ('database hostname', tools.config['db_host'] or 'localhost'),
76 ('database port', tools.config['db_port'] or '5432'),
77 ('database user', tools.config['db_user'])]:
78 logger.notifyChannel("server", netsvc.LOG_INFO, "%s - %s" % ( name, value ))
82 if sys.platform == 'win32':
84 mx.DateTime.strptime = lambda x, y: mx.DateTime.mktime(time.strptime(x, y))
86 #----------------------------------------------------------
88 #----------------------------------------------------------
89 logger.notifyChannel("objects", netsvc.LOG_INFO, 'initialising distributed objects services')
91 #---------------------------------------------------------------
92 # connect to the database and initialize it with base if needed
93 #---------------------------------------------------------------
96 #----------------------------------------------------------
97 # import basic modules
98 #----------------------------------------------------------
104 #----------------------------------------------------------
106 #----------------------------------------------------------
110 #----------------------------------------------------------
111 # Load and update databases if requested
112 #----------------------------------------------------------
114 import service.http_server
116 if not ( tools.config["stop_after_init"] or \
117 tools.config["translate_in"] or \
118 tools.config["translate_out"] ):
119 service.http_server.init_servers()
120 service.http_server.init_xmlrpc()
122 import service.netrpc_server
123 service.netrpc_server.init_servers()
125 if tools.config['db_name']:
126 for db in tools.config['db_name'].split(','):
127 pooler.get_db_and_pool(db, update_module=tools.config['init'] or tools.config['update'])
129 #----------------------------------------------------------
131 #----------------------------------------------------------
132 if tools.config["translate_out"]:
135 if tools.config["language"]:
136 msg = "language %s" % (tools.config["language"],)
139 logger.notifyChannel("init", netsvc.LOG_INFO,
140 'writing translation file for %s to %s' % (msg,
141 tools.config["translate_out"]))
143 fileformat = os.path.splitext(tools.config["translate_out"])[-1][1:].lower()
144 buf = file(tools.config["translate_out"], "w")
145 tools.trans_export(tools.config["language"], tools.config["translate_modules"], buf, fileformat)
148 logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written successfully')
151 if tools.config["translate_in"]:
152 tools.trans_load(tools.config["db_name"],
153 tools.config["translate_in"],
154 tools.config["language"])
157 #----------------------------------------------------------------------------------
158 # if we don't want the server to continue to run after initialization, we quit here
159 #----------------------------------------------------------------------------------
160 if tools.config["stop_after_init"]:
164 #----------------------------------------------------------
166 #----------------------------------------------------------
168 LST_SIGNALS = ['SIGINT', 'SIGTERM']
169 if os.name == 'posix':
170 LST_SIGNALS.extend(['SIGUSR1','SIGQUIT'])
174 [(getattr(signal, sign), sign) for sign in LST_SIGNALS]
177 def handler(signum, _):
179 :param signum: the signal number
183 netsvc.Server.quitAll()
184 if tools.config['pidfile']:
185 os.unlink(tools.config['pidfile'])
186 logger.notifyChannel('shutdown', netsvc.LOG_INFO,
187 "Shutdown Server! - %s" % ( SIGNALS[signum], ))
191 for signum in SIGNALS:
192 signal.signal(signum, handler)
194 if tools.config['pidfile']:
195 fd = open(tools.config['pidfile'], 'w')
196 pidtext = "%d" % (os.getpid())
201 netsvc.Server.startAll()
203 logger.notifyChannel("web-services", netsvc.LOG_INFO,
204 'the server is running, waiting for connections...')
209 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: