summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/keystone-all11
-rw-r--r--etc/keystone.conf.sample6
-rw-r--r--keystone/common/systemd.py40
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()