6c5f7d9e10
Fixes bug 980037 Service managers starting keystone-all have no way of being notified when the service is ready to accept connections. This commit allows a configurable command to be called when we are ready e.g. for systemd setting the statup type of a service unit to "notify" and setting onready = systemd-notify --ready in keystone.conf, would notify a waiting systemd that we are ready to serve In an automated envirnment (e.g. puppet) this will allow the startup of the keystone-all service (with systemctl for example) directly followed by usage of the keystone client without the need for a sleep (or retry) while we are waiting for the keystone service to be ready. Change-Id: I3f7aafe9837be60a0f35cae1a7db892f6851cc47
88 lines
2.5 KiB
Python
Executable File
88 lines
2.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
import greenlet
|
|
import logging
|
|
import os
|
|
import sys
|
|
|
|
# If ../keystone/__init__.py exists, add ../ to Python search path, so that
|
|
# it will override what happens to be installed in /usr/(local/)lib/python...
|
|
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(__file__),
|
|
os.pardir,
|
|
os.pardir))
|
|
if os.path.exists(os.path.join(possible_topdir,
|
|
'keystone',
|
|
'__init__.py')):
|
|
sys.path.insert(0, possible_topdir)
|
|
|
|
from paste import deploy
|
|
|
|
from keystone import config
|
|
from keystone.common import wsgi
|
|
from keystone.common import utils
|
|
|
|
|
|
CONF = config.CONF
|
|
|
|
|
|
def create_server(conf, name, host, port):
|
|
app = deploy.loadapp('config:%s' % conf, name=name)
|
|
return wsgi.Server(app, host=host, port=port)
|
|
|
|
|
|
def serve(*servers):
|
|
for server in servers:
|
|
logging.debug("starting server %s on port %s",
|
|
server.application,
|
|
server.port)
|
|
server.start()
|
|
|
|
# notify calling process we are ready to serve
|
|
if CONF.onready:
|
|
try:
|
|
utils.check_output(CONF.onready.split())
|
|
except Exception:
|
|
logging.exception('Failed to execute onready command')
|
|
|
|
for server in servers:
|
|
try:
|
|
server.wait()
|
|
except greenlet.GreenletExit:
|
|
pass
|
|
|
|
|
|
if __name__ == '__main__':
|
|
dev_conf = os.path.join(possible_topdir,
|
|
'etc',
|
|
'keystone.conf')
|
|
config_files = None
|
|
if os.path.exists(dev_conf):
|
|
config_files = [dev_conf]
|
|
|
|
CONF(config_files=config_files, args=sys.argv)
|
|
|
|
config.setup_logging(CONF)
|
|
|
|
# Log the options used when starting if we're in debug mode...
|
|
if CONF.debug:
|
|
CONF.log_opt_values(logging.getLogger(CONF.prog), logging.DEBUG)
|
|
|
|
if not CONF.config_file:
|
|
print "No config files could be found."
|
|
CONF.print_help()
|
|
sys.exit(1)
|
|
|
|
options = deploy.appconfig('config:%s' % CONF.config_file[0])
|
|
|
|
servers = []
|
|
servers.append(create_server(CONF.config_file[0],
|
|
'admin',
|
|
CONF.bind_host,
|
|
int(CONF.admin_port)))
|
|
servers.append(create_server(CONF.config_file[0],
|
|
'main',
|
|
CONF.bind_host,
|
|
int(CONF.public_port)))
|
|
serve(*servers)
|