Merge health_checks.d framework.

This commit is contained in:
Adam Gandelman 2013-03-06 13:29:09 -08:00
commit c57b35ad24
7 changed files with 76 additions and 3 deletions

View File

@ -277,6 +277,13 @@ function config_changed() {
fi
service_ctl all restart
# Save our scriptrc env variables for health checks
declare -a env_vars=(
"OPENSTACK_PORT_MCASTPORT=$(config-get ha-mcastport)"
'OPENSTACK_SERVICE_API=glance-api'
'OPENSTACK_SERVICE_REGISTRY=glance-registry')
save_script_rc ${env_vars[@]}
}
function cluster_changed() {

View File

@ -324,7 +324,7 @@ HAPROXY_DEFAULT=/etc/default/haproxy
##########################################################################
# Description: Configures HAProxy services for Openstack API's
# Parameters:
# Parameters:
# Space delimited list of service:port combinations for which
# haproxy service configuration should be generated for. The function
# assumes the name of the peer relation is 'cluster' and that every
@ -332,7 +332,7 @@ HAPROXY_DEFAULT=/etc/default/haproxy
#
# The HAProxy service will listen on port + 10000.
# Example:
# configure_haproxy cinder_api:12345 nova_api:9999
# configure_haproxy cinder_api:12345 nova_api:9999
##########################################################################
configure_haproxy() {
local address=`unit-get private-address`
@ -525,3 +525,39 @@ if value.startswith('%'): exit(0)
print value
"
}
##########################################################################
# Description: Creates an rc file exporting environment variables to a
# script_path local to the charm's installed directory.
# 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
#
# Parameters:
# An array of '=' delimited ENV_VAR:value combinations to export.
# If optional script_path key is not provided in the array, script_path
# defaults to scripts/scriptrc
##########################################################################
function save_script_rc {
if [ ! -n "$JUJU_UNIT_NAME" ]; then
echo "Error: Missing JUJU_UNIT_NAME environment variable"
exit 1
fi
# our default unit_path
unit_path="/var/lib/juju/units/${JUJU_UNIT_NAME/\//-}/charm/scripts/scriptrc"
echo $unit_path
tmp_rc="/tmp/${JUJU_UNIT_NAME/\//-}rc"
echo "#!/bin/bash" > $tmp_rc
for env_var in "${@}"
do
if `echo $env_var | grep -q script_path`; then
# well then we need to reset the new unit-local script path
unit_path="/var/lib/juju/units/${JUJU_UNIT_NAME/\//-}/charm/${env_var/script_path=/}"
else
echo "export $env_var" >> $tmp_rc
fi
done
chmod 755 $tmp_rc
mv $tmp_rc $unit_path
}

View File

@ -1 +1 @@
83
84

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,13 @@
#!/bin/bash
# Validate that service is running
HEALTH_DIR=`dirname $0`
SCRIPTS_DIR=`dirname $HEALTH_DIR`
. $SCRIPTS_DIR/scriptrc
set -e
# Grab any OPENSTACK_SERVICE* environment variables
openstack_service_names=`env| awk -F '=' '(/OPENSTACK_SERVICE/){print $2}'`
for service_name in $openstack_service_names
do
service $service_name status 2>/dev/null | grep -q running
done

2
scripts/remove_from_cluster Executable file
View File

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