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
This commit is contained in:
parent
e86dc75725
commit
0d78da501f
@ -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}}
|
||||
|
@ -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 <<eof
|
||||
start on runlevel [2345]
|
||||
task
|
||||
exec os-refresh-config
|
||||
eof
|
||||
|
||||
# Systemd
|
||||
elif [ -d /lib/systemd/system ] ; then
|
||||
cat > /lib/systemd/system/os-refresh-config.service <<eof
|
||||
[Unit]
|
||||
Description=Refresh Config on state change
|
||||
After=cloud-final.service
|
||||
Before=crond.service
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/os-refresh-config
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
eof
|
||||
|
||||
# Make systemd take notice of it
|
||||
systemctl daemon-reload
|
||||
|
||||
# Enable the service
|
||||
systemctl enable os-refresh-config.service
|
||||
|
||||
else
|
||||
echo Only systems with systemd or upstart are supported.
|
||||
exit 1
|
||||
fi
|
||||
|
@ -1,9 +1,12 @@
|
||||
#!/bin/bash
|
||||
install -m 0755 -o root -g root $(dirname $0)/cfn-hup-wrapper /usr/local/bin/cfn-hup-wrapper
|
||||
# This cannot be an os-apply-config template as this is what runs
|
||||
# os-apply-config for the first time.
|
||||
cat > /etc/cron.d/cfn-hup <<EOF
|
||||
# This is a workaround for cfn-hup not actually being a daemon
|
||||
SHELL=/bin/sh
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
|
||||
*/5 * * * * root cfn-hup-wrapper
|
||||
# Ensure cfn-hup has a configuration
|
||||
@reboot root os-refresh-config 2>&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
|
||||
|
@ -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)
|
Loading…
Reference in New Issue
Block a user