From eaa1834b972b090b8dc66da906fe4707a4239362 Mon Sep 17 00:00:00 2001 From: Adam Gandelman Date: Thu, 4 Apr 2013 19:34:08 -0400 Subject: [PATCH] Avoid excessive svc restarts by tracking CONFIG_CHANGED. --- hooks/glance-common | 13 ++++++++++--- hooks/glance-relations | 2 -- hooks/lib/openstack-common | 14 +++++++++++++- revision | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/hooks/glance-common b/hooks/glance-common index e471cbe4..06e8f362 100755 --- a/hooks/glance-common +++ b/hooks/glance-common @@ -11,6 +11,8 @@ GLANCE_API_CONF="/etc/glance/glance-api.conf" GLANCE_API_PASTE_INI="/etc/glance/glance-api-paste.ini" CONF_DIR="/etc/glance" +# Flag used to track config changes. +CONFIG_CHANGED="False" if [[ -e "$CHARM_DIR/lib/openstack-common" ]] ; then . $CHARM_DIR/lib/openstack-common else @@ -18,6 +20,8 @@ else fi function set_paste_deploy_flavor { + # NOTE(adam_g): If we want to benefit from CONFIG_CHANGED here, + # needs to be updated to detect already config'd settings. local flavor="$1" local config="$2" case $config in @@ -27,12 +31,14 @@ function set_paste_deploy_flavor { esac if ! grep -q "\[paste_deploy\]" "$conf" ; then juju-log "Updating $conf: Setting new paste_deploy flavor = $flavor" - echo -e "\n[paste_deploy]\nflavor = keystone\n" >>$conf && return 0 + echo -e "\n[paste_deploy]\nflavor = keystone\n" >>$conf && + CONFIG_CHANGED="True" && return 0 juju-log "ERROR: Could not update paste_deploy flavor in $conf" && return 1 fi juju-log "Updating $conf: Setting paste_deploy flavor = $flavor" local tag="[paste_deploy]" - sed -i "/$tag/, +1 s/\(flavor = \).*/\1$flavor/g" $conf && return 0 + sed -i "/$tag/, +1 s/\(flavor = \).*/\1$flavor/g" $conf && + CONFIG_CHANGED="True" && return 0 juju-log "ERROR: Could not update paste_deploy flavor in $conf" && return 1 } @@ -77,12 +83,13 @@ function set_or_update { [[ -z $VALUE ]] && juju-log "ERROR: set_or_update(): key $KEY missing value" \ && exit 1 cat $CONF | grep "$KEY = $VALUE" >/dev/null \ - && juju-log "glance: $KEY = $VALUE already set" exit 0 + && juju-log "glance: $KEY = $VALUE already set" && return 0 if cat $CONF | grep "$KEY =" >/dev/null ; then sed -i "s|\($KEY = \).*|\1$VALUE|" $CONF else echo "$KEY = $VALUE" >>$CONF fi + CONFIG_CHANGED="True" } do_openstack_upgrade() { diff --git a/hooks/glance-relations b/hooks/glance-relations index 6175fde0..4667ff5b 100755 --- a/hooks/glance-relations +++ b/hooks/glance-relations @@ -71,8 +71,6 @@ function db_changed { juju-log "$CHARM - db_changed: Configuring glance.conf for access to $glance_db" - service_ctl all stop - set_or_update sql_connection "mysql://$db_user:$db_password@$db_host/$glance_db" registry # since folsom, a db connection setting in glance-api.conf is required. diff --git a/hooks/lib/openstack-common b/hooks/lib/openstack-common index a3ecfc1f..77ce75e7 100644 --- a/hooks/lib/openstack-common +++ b/hooks/lib/openstack-common @@ -20,6 +20,9 @@ function service_ctl_status { function service_ctl { # control a specific service, or all (as defined by $SERVICES) + # service restarts will only occur depending on global $CONFIG_CHANGED, + # which should be updated in charm's set_or_update(). + local config_changed=${CONFIG_CHANGED:-True} if [[ $1 == "all" ]] ; then ctl="$SERVICES" else @@ -37,12 +40,21 @@ function service_ctl { "stop") service_ctl_status $i && service $i stop || return 0 ;; "restart") - service_ctl_status $i && service $i restart || service $i start ;; + if [[ "$config_changed" == "True" ]] ; then + service_ctl_status $i && service $i restart || service $i start + fi + ;; esac if [[ $? != 0 ]] ; then juju-log "$CHARM: service_ctl ERROR - Service $i failed to $action" fi done + # all configs should have been reloaded on restart of all services, reset + # flag if its being used. + if [[ "$action" == "restart" ]] && [[ -n "$CONFIG_CHANGED" ]] && + [[ "$ctl" == "all" ]]; then + CONFIG_CHANGED="False" + fi } function configure_install_source { diff --git a/revision b/revision index 94361d49..dee261df 100644 --- a/revision +++ b/revision @@ -1 +1 @@ -132 +140