From 0eded3adc0c07330a77087ac0e0905e4901c13c5 Mon Sep 17 00:00:00 2001 From: Chad Smith Date: Tue, 26 Feb 2013 10:26:20 -0700 Subject: [PATCH] -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 --- hooks/horizon-relations | 8 +++++ hooks/lib/openstack-common | 37 ++++++++++++++++++++++ revision | 2 +- scripts/add_to_cluster | 2 ++ scripts/health_checks.d/service_ports_live | 13 ++++++++ scripts/health_checks.d/service_running | 13 ++++++++ scripts/health_checks.d/service_url_checks | 16 ++++++++++ scripts/remove_from_cluster | 2 ++ 8 files changed, 92 insertions(+), 1 deletion(-) create mode 100755 scripts/add_to_cluster create mode 100755 scripts/health_checks.d/service_ports_live create mode 100755 scripts/health_checks.d/service_running create mode 100644 scripts/health_checks.d/service_url_checks create mode 100755 scripts/remove_from_cluster diff --git a/hooks/horizon-relations b/hooks/horizon-relations index d2c40ee3..6ca2c659 100755 --- a/hooks/horizon-relations +++ b/hooks/horizon-relations @@ -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)" diff --git a/hooks/lib/openstack-common b/hooks/lib/openstack-common index 720a50af..5c479b39 100644 --- a/hooks/lib/openstack-common +++ b/hooks/lib/openstack-common @@ -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 diff --git a/revision b/revision index 2bd5a0a9..40994076 100644 --- a/revision +++ b/revision @@ -1 +1 @@ -22 +23 diff --git a/scripts/add_to_cluster b/scripts/add_to_cluster new file mode 100755 index 00000000..e50ab019 --- /dev/null +++ b/scripts/add_to_cluster @@ -0,0 +1,2 @@ +#!/bin/bash +crm node online diff --git a/scripts/health_checks.d/service_ports_live b/scripts/health_checks.d/service_ports_live new file mode 100755 index 00000000..54eccb72 --- /dev/null +++ b/scripts/health_checks.d/service_ports_live @@ -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 diff --git a/scripts/health_checks.d/service_running b/scripts/health_checks.d/service_running new file mode 100755 index 00000000..8fe56e13 --- /dev/null +++ b/scripts/health_checks.d/service_running @@ -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 diff --git a/scripts/health_checks.d/service_url_checks b/scripts/health_checks.d/service_url_checks new file mode 100644 index 00000000..6a67bbfc --- /dev/null +++ b/scripts/health_checks.d/service_url_checks @@ -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 + diff --git a/scripts/remove_from_cluster b/scripts/remove_from_cluster new file mode 100755 index 00000000..4fb2aa16 --- /dev/null +++ b/scripts/remove_from_cluster @@ -0,0 +1,2 @@ +#!/bin/bash +crm node standby