Merge health_checks.d framework.

This commit is contained in:
Adam Gandelman
2013-03-06 14:31:50 -08:00
6 changed files with 53 additions and 0 deletions

View File

@@ -245,3 +245,19 @@ def configure_haproxy(units, service_ports, template_dir=None):
f.write(template.render(context))
with open(HAPROXY_DEFAULT, 'w') as f:
f.write('ENABLED=1')
def save_script_rc(script_path="scripts/scriptrc", **env_vars):
"""
Write an rc file in the charm-delivered directory containing
exported environment variables provided by env_vars. Any charm scripts run
outside the juju hook environment can source this scriptrc to obtain
updated config information necessary to perform health checks or
service changes.
"""
unit_name = os.getenv('JUJU_UNIT_NAME').replace('/', '-')
juju_rc_path="/var/lib/juju/units/%s/charm/%s" % (unit_name, script_path)
with open(juju_rc_path, 'wb') as rc_script:
rc_script.write(
"#!/bin/bash\n")
[rc_script.write('export %s=%s\n' % (u, p))
for u, p in env_vars.iteritems() if u != "script_path"]

View File

@@ -167,6 +167,11 @@ def write_proxy_config():
import multiprocessing
workers = multiprocessing.cpu_count()
env_vars = {'OPENSTACK_SERVICE_SWIFT': 'proxy-server',
'OPENSTACK_PORT_API': bind_port,
'OPENSTACK_PORT_MEMCACHED': 11211}
openstack.save_script_rc(**env_vars)
ctxt = {
'proxy_ip': utils.get_host_ip(),
'bind_port': bind_port,

2
scripts/add_to_cluster Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
crm node online

View File

@@ -0,0 +1,13 @@
#!/bin/bash
# Validate that service ports are active
HEALTH_DIR=`dirname $0`
SCRIPTS_DIR=`dirname $HEALTH_DIR`
. $SCRIPTS_DIR/scriptrc
set -e
# Grab any OPENSTACK_PORT* environment variables
openstack_ports=`env| awk -F '=' '(/OPENSTACK_PORT/){print $2}'`
for port in $openstack_ports
do
netstat -ln | grep -q ":$port "
done

View File

@@ -0,0 +1,15 @@
#!/bin/bash
# Validate that service is running
HEALTH_DIR=`dirname $0`
SCRIPTS_DIR=`dirname $HEALTH_DIR`
. $SCRIPTS_DIR/scriptrc
set -e
# Grab any OPENSTACK_SWIFT_SERVICE* environment variables
openstack_service_names=`env| awk -F '=' '(/OPENSTACK_SWIFT_SERVICE/){print $2}'`
for service_name in $openstack_service_names
do
# Double-negative: we want to ensure swift-init does not return
# 'No <service_name> running'
swift-init $service_name status 2>/dev/null | grep -vq "No $service_name running"
done

2
scripts/remove_from_cluster Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
crm node standby