-add health_checks.d, add_to_cluster and remove_from_cluster scripts

-create a bash save_script_rc function which creates a local scriptrc file
 comparable to our python-based function
This commit is contained in:
Chad Smith
2013-02-26 10:26:20 -07:00
parent 284d9cf4e9
commit 0eded3adc0
8 changed files with 92 additions and 1 deletions

View File

@@ -79,6 +79,14 @@ function config_changed {
set_or_update LOGIN_URL "$web_root/auth/login"
set_or_update LOGIN_REDIRECT_URL "$web_root"
# Save our scriptrc env variables for health checks
declare -a env_vars=(
'OPENSTACK_URL_HORIZON_CHECK=http://localhost/$web_root|Login - Openstack'
'OPENSTACK_SERVICE_HORIZON=apache2'
'OPENSTACK_PORT_HORIZON=80')
save_script_rc ${env_vars[@]}
# Set default role and trigger a identity-service relation event to
# ensure role is created in keystone.
set_or_update OPENSTACK_KEYSTONE_DEFAULT_ROLE "$(config-get default-role)"

View File

@@ -315,6 +315,43 @@ function get_block_device() {
return 0
}
##########################################################################
# 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
}
HAPROXY_CFG=/etc/haproxy/haproxy.cfg
HAPROXY_DEFAULT=/etc/default/haproxy

View File

@@ -1 +1 @@
22
23

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

View File

@@ -0,0 +1,16 @@
#!/bin/bash
# Validate that service urls return expected content
HEALTH_DIR=`dirname $0`
SCRIPTS_DIR=`dirname $HEALTH_DIR`
. $SCRIPTS_DIR/scriptrc
set -e
# Grab any OPENSTACK_URL* environment variables and validate content response
openstack_urls=`env| awk -F '=' '(/OPENSTACK_URL/){print $2}'`
for url_check in $openstack_urls
do
url=`echo $url_check| awk -F '|' '{print $1}'`
expected_content=`echo $url_check| awk -F '|' '{print $2}'`
wget -q -O - $url | grep -q "$expected_content"
done

2
scripts/remove_from_cluster Executable file
View File

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