From 0d78da501fc72fe4db56ff018de9b5cfb40bea87 Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Mon, 15 Jul 2013 22:11:24 -0700 Subject: [PATCH] Do not automatically start os-refresh-config. cfn-hup needs to be the only thing running os-refresh-config. Otherwise the other orc scripts will race with cfn-hup writing out new metadata. The exception introduced here is to also let crond (which runs cfn-hup) run os-refresh-config @reboot to seed the configuration. Without a need to start up automatically, there doesn't seem to be any good reason to use an upstart job / systemd service unit. Instead we can just pipe os-refresh-config output to logger. Also because we have several places to run os-refresh-config, we need to move the locking into os-refresh-config itself. Please see https://review.openstack.org/37319 for that change. Change-Id: Ic35eca943ba76d421b61710b9fff018e17fb40bf --- .../os-config-applier/etc/cfn/hooks.conf | 2 +- .../install.d/01-os-refresh-config | 34 ---------------- .../install.d/75-cfn-hup-cronjob | 9 +++-- .../install.d/cfn-hup-wrapper | 39 ------------------- 4 files changed, 7 insertions(+), 77 deletions(-) delete mode 100644 elements/os-refresh-config/install.d/cfn-hup-wrapper diff --git a/elements/heat-cfntools/os-config-applier/etc/cfn/hooks.conf b/elements/heat-cfntools/os-config-applier/etc/cfn/hooks.conf index 09b42891f..7f56549ad 100644 --- a/elements/heat-cfntools/os-config-applier/etc/cfn/hooks.conf +++ b/elements/heat-cfntools/os-config-applier/etc/cfn/hooks.conf @@ -2,7 +2,7 @@ [os-refresh-config-{{resource}}] triggers=post.add,post.delete.post.update path=Resources.{{resource}}.Metadata -action=service os-refresh-config start +action=os-refresh-config 2>&1 | logger -t os-refresh-config runas=root {{/heat.refresh}} diff --git a/elements/os-refresh-config/install.d/01-os-refresh-config b/elements/os-refresh-config/install.d/01-os-refresh-config index fad7548c9..81b1a87ce 100755 --- a/elements/os-refresh-config/install.d/01-os-refresh-config +++ b/elements/os-refresh-config/install.d/01-os-refresh-config @@ -11,37 +11,3 @@ pip install git+https://github.com/stackforge/os-refresh-config.git for d in pre-configure.d configure.d migration.d post-configure.d; do install -m 0755 -o root -g root -d /opt/stack/os-config-refresh/$d done - -# Upstart -if [ -d /etc/init ] ; then - cat > /etc/init/os-refresh-config.conf < /lib/systemd/system/os-refresh-config.service < /etc/cron.d/cfn-hup <&1 | logger -t os-refresh-config +# This is a workaround for cfn-hup not actually being a daemon +*/5 * * * * root cfn-hup --no-daemon EOF diff --git a/elements/os-refresh-config/install.d/cfn-hup-wrapper b/elements/os-refresh-config/install.d/cfn-hup-wrapper deleted file mode 100644 index f2b49b063..000000000 --- a/elements/os-refresh-config/install.d/cfn-hup-wrapper +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env python -# -# 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. - -import fcntl -import os -import random -import subprocess -import sys -import time - -if len(sys.argv) > 1: - max_sleep = int(sys.argv[1]) -else: - max_sleep = 59 - -randskew = random.randint(0, max_sleep) -time.sleep(randskew) -with open('/run/os-refresh-config-cfn-hup.lock', 'a') as lock: - fcntl.flock(lock, fcntl.LOCK_EX) - lock.seek(0) - lock.truncate() - lock.write('Lock held by process id %s\n' % os.getpid()) - lock.flush() - try: - subprocess.check_call(['cfn-hup', '--no-daemon']) - except subprocess.CalledProcessError as e: - sys.stderr.write("%s\n" % e) - sys.exit(e.returncode)