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 #----------------------------------------------------------
42 __author__ = release.author
43 __version__ = release.version
45 # We DON't log this using the standard logger, because we might mess
46 # with the logfile's permissions. Just do a quick exit here.
47 if pwd.getpwuid(os.getuid())[0] == 'root' :
48 sys.stderr.write("Attempted to run OpenERP server as root. This is not good, aborting.\n")
51 #----------------------------------------------------------
53 #----------------------------------------------------------
55 logger = netsvc.Logger()
57 #-----------------------------------------------------------------------
58 # import the tools module so that the commandline parameters are parsed
59 #-----------------------------------------------------------------------
62 logger.notifyChannel("server", netsvc.LOG_INFO, "version - %s" % release.version )
63 for name, value in [('addons_path', tools.config['addons_path']),
64 ('database hostname', tools.config['db_host'] or 'localhost'),
65 ('database port', tools.config['db_port'] or '5432'),
66 ('database user', tools.config['db_user'])]:
67 logger.notifyChannel("server", netsvc.LOG_INFO, "%s - %s" % ( name, value ))
69 # Don't allow if the connection to PostgreSQL done by postgres user
70 if tools.config['db_user'] == 'postgres':
71 logger.notifyChannel("server", netsvc.LOG_ERROR, "%s" % ("Attempted to connect database with postgres user. This is a security flaws, aborting."))
76 #----------------------------------------------------------
78 #----------------------------------------------------------
79 logger.notifyChannel("objects", netsvc.LOG_INFO, 'initialising distributed objects services')
81 #---------------------------------------------------------------
82 # connect to the database and initialize it with base if needed
83 #---------------------------------------------------------------
86 #----------------------------------------------------------
87 # import basic modules
88 #----------------------------------------------------------
94 #----------------------------------------------------------
96 #----------------------------------------------------------
100 #----------------------------------------------------------
101 # Load and update databases if requested
102 #----------------------------------------------------------
104 import service.http_server
106 if not ( tools.config["stop_after_init"] or \
107 tools.config["translate_in"] or \
108 tools.config["translate_out"] ):
109 service.http_server.init_servers()
110 service.http_server.init_xmlrpc()
111 service.http_server.init_static_http()
113 import service.netrpc_server
114 service.netrpc_server.init_servers()
116 if tools.config['db_name']:
117 for dbname in tools.config['db_name'].split(','):
118 db,pool = pooler.get_db_and_pool(dbname, update_module=tools.config['init'] or tools.config['update'], pooljobs=False)
119 if tools.config["test_file"]:
120 logger.notifyChannel("init", netsvc.LOG_INFO,
121 'loading test file %s' % (tools.config["test_file"],))
123 tools.convert_yaml_import(cr, 'base', file(tools.config["test_file"]), {}, 'test', True)
125 pool.get('ir.cron')._poolJobs(db.dbname)
127 #----------------------------------------------------------
129 #----------------------------------------------------------
130 if tools.config["translate_out"]:
133 if tools.config["language"]:
134 msg = "language %s" % (tools.config["language"],)
137 logger.notifyChannel("init", netsvc.LOG_INFO,
138 'writing translation file for %s to %s' % (msg,
139 tools.config["translate_out"]))
141 fileformat = os.path.splitext(tools.config["translate_out"])[-1][1:].lower()
142 buf = file(tools.config["translate_out"], "w")
143 tools.trans_export(tools.config["language"], tools.config["translate_modules"], buf, fileformat)
146 logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written successfully')
149 if tools.config["translate_in"]:
150 tools.trans_load(tools.config["db_name"],
151 tools.config["translate_in"],
152 tools.config["language"])
155 #----------------------------------------------------------------------------------
156 # if we don't want the server to continue to run after initialization, we quit here
157 #----------------------------------------------------------------------------------
158 if tools.config["stop_after_init"]:
162 #----------------------------------------------------------
164 #----------------------------------------------------------
166 LST_SIGNALS = ['SIGINT', 'SIGTERM']
167 if os.name == 'posix':
168 LST_SIGNALS.extend(['SIGUSR1','SIGQUIT'])
172 [(getattr(signal, sign), sign) for sign in LST_SIGNALS]
175 def handler(signum, _):
177 :param signum: the signal number
181 netsvc.Server.quitAll()
182 if tools.config['pidfile']:
183 os.unlink(tools.config['pidfile'])
184 logger.notifyChannel('shutdown', netsvc.LOG_INFO,
185 "Shutdown Server! - %s" % ( SIGNALS[signum], ))
189 for signum in SIGNALS:
190 signal.signal(signum, handler)
192 if tools.config['pidfile']:
193 fd = open(tools.config['pidfile'], 'w')
194 pidtext = "%d" % (os.getpid())
199 netsvc.Server.startAll()
201 logger.notifyChannel("web-services", netsvc.LOG_INFO,
202 'the server is running, waiting for connections...')
207 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: