diff options
| author | Alan Pevec <apevec@redhat.com> | 2012-07-02 14:07:06 +0200 |
|---|---|---|
| committer | Alan Pevec <apevec@redhat.com> | 2012-07-04 00:36:20 +0200 |
| commit | abc06716d027d68f0da3b0f559fa7c85a21804d5 (patch) | |
| tree | 7c64eb47b5a0ba12e0688d7a754254f53ebb0d2d | |
| parent | 478cde128b4e1c6f8aa4595b71552207197917cd (diff) | |
notify calling process we are ready to serve
Fixes bug 980037 again
Systemd notification should be sent in-process, otherwise systemd might
miss the subprocess sending notification.
See systemd bug https://bugzilla.redhat.com/show_bug.cgi?id=820448
Change-Id: Iccc51cf77af5598ee6b4c3cd69a12a7ee9fc2eb5
| -rwxr-xr-x | bin/keystone-all | 11 | ||||
| -rw-r--r-- | etc/keystone.conf.sample | 6 | ||||
| -rw-r--r-- | keystone/common/systemd.py | 40 |
3 files changed, 52 insertions, 5 deletions
diff --git a/bin/keystone-all b/bin/keystone-all index fc499967..c7734cf2 100755 --- a/bin/keystone-all +++ b/bin/keystone-all @@ -22,6 +22,7 @@ from paste import deploy from keystone import config from keystone.common import wsgi from keystone.common import utils +from keystone.openstack.common import importutils CONF = config.CONF @@ -54,9 +55,13 @@ def serve(*servers): # 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') + notifier = importutils.import_module(CONF.onready) + notifier.notify() + except ImportError: + try: + utils.check_output(CONF.onready.split()) + except Exception: + logging.exception('Failed to execute onready command') for server in servers: try: diff --git a/etc/keystone.conf.sample b/etc/keystone.conf.sample index f3849d3e..9128ee7e 100644 --- a/etc/keystone.conf.sample +++ b/etc/keystone.conf.sample @@ -46,9 +46,11 @@ # Format string for %(asctime)s in log records. # log_date_format = %Y-%m-%d %H:%M:%S -# onready allows you to run a command when the process is ready to serve -# for example to have it notify using systemd, one could set +# onready allows you to send a notification when the process is ready to serve +# For example, to have it notify using systemd, one could set shell command: # onready = systemd-notify --ready +# or a module with notify() method: +# onready = keystone.common.systemd [sql] # The SQLAlchemy connection string used to connect to the database diff --git a/keystone/common/systemd.py b/keystone/common/systemd.py new file mode 100644 index 00000000..f8d3f367 --- /dev/null +++ b/keystone/common/systemd.py @@ -0,0 +1,40 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Helper module for systemd start-up completion notification. +Used for "onready" configuration parameter in keystone.conf +""" + +import os +import socket + + +def _sd_notify(msg): + sysd = os.getenv('NOTIFY_SOCKET') + if sysd: + sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) + sock.connect(sysd) + sock.sendall(msg) + sock.close() + + +def notify(): + _sd_notify('READY=1') + + +if __name__ == '__main__': + notify() |
