[openstack-keystone] set systemd service to restart on abort

Alan Pevec apevec at fedoraproject.org
Tue Jul 31 00:31:07 UTC 2012


commit cfe28e62217f8a46b8a37984ca7d6d9c6b908311
Author: Alan Pevec <apevec at redhat.com>
Date:   Mon Jul 30 16:59:23 2012 +0200

    set systemd service to restart on abort
    
    also change systemd service to wait for notification when it's ready to serve
    Requires upstream patch
    https://github.com/openstack/keystone/commit/abc06716d027d68f0da3b0f559fa7c85a21804d5

 ...ify-calling-process-we-are-ready-to-serve.patch |  112 ++++++++++++++++++++
 openstack-keystone.service                         |    3 +-
 openstack-keystone.spec                            |   10 ++-
 3 files changed, 122 insertions(+), 3 deletions(-)
---
diff --git a/0001-notify-calling-process-we-are-ready-to-serve.patch b/0001-notify-calling-process-we-are-ready-to-serve.patch
new file mode 100644
index 0000000..910c80a
--- /dev/null
+++ b/0001-notify-calling-process-we-are-ready-to-serve.patch
@@ -0,0 +1,112 @@
+From dfc814c514d94fab1c45b477b813d1e580998e0c Mon Sep 17 00:00:00 2001
+From: Alan Pevec <apevec at redhat.com>
+Date: Mon, 2 Jul 2012 14:07:06 +0200
+Subject: [PATCH] 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
+---
+ bin/keystone-all           |   11 ++++++++---
+ etc/keystone.conf.sample   |    6 ++++--
+ keystone/common/systemd.py |   40 ++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 52 insertions(+), 5 deletions(-)
+ create mode 100644 keystone/common/systemd.py
+
+diff --git a/bin/keystone-all b/bin/keystone-all
+index fc49996..c7734cf 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 b85602d..ac5b440 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 0000000..f8d3f36
+--- /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()
diff --git a/openstack-keystone.service b/openstack-keystone.service
index 2f8a4c1..163c36f 100644
--- a/openstack-keystone.service
+++ b/openstack-keystone.service
@@ -3,7 +3,8 @@ Description=OpenStack Identity Service (code-named Keystone)
 After=syslog.target network.target
 
 [Service]
-Type=simple
+Type=notify
+Restart=on-abort
 User=keystone
 ExecStart=/usr/bin/keystone-all --config-file /etc/keystone/keystone.conf
 
diff --git a/openstack-keystone.spec b/openstack-keystone.spec
index b6e8659..a70cf77 100644
--- a/openstack-keystone.spec
+++ b/openstack-keystone.spec
@@ -24,11 +24,14 @@ Source1:        openstack-keystone.logrotate
 Source2:        openstack-keystone.service
 Source5:        openstack-keystone-sample-data
 
-Patch0:         match-egg-and-spec-requires.patch
 
 #
 # patches_base=folsom-2
 #
+Patch0001: 0001-notify-calling-process-we-are-ready-to-serve.patch
+
+# RPM specific
+Patch9999:         match-egg-and-spec-requires.patch
 
 BuildArch:      noarch
 BuildRequires:  python2-devel
@@ -110,7 +113,9 @@ This package contains documentation for Keystone.
 %prep
 %setup -q -n keystone-%{version}
 
-%patch0 -p1
+%patch0001 -p1
+
+%patch9999 -p1
 
 find . \( -name .gitignore -o -name .placeholder \) -delete
 find keystone -name \*.py -exec sed -i '/\/usr\/bin\/env python/d' {} \;
@@ -126,6 +131,7 @@ openstack-config --set etc/keystone.conf catalog driver keystone.catalog.backend
 openstack-config --set etc/keystone.conf identity driver keystone.identity.backends.sql.Identity
 openstack-config --set etc/keystone.conf token driver keystone.token.backends.sql.Token
 openstack-config --set etc/keystone.conf ec2 driver keystone.contrib.ec2.backends.sql.Ec2
+openstack-config --set etc/keystone.conf DEFAULT onready keystone.common.systemd
 
 %{__python} setup.py build
 


More information about the scm-commits mailing list