Avoid excessive svc restarts by tracking CONFIG_CHANGED.
This commit is contained in:
parent
79593bbf34
commit
eaa1834b97
@ -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() {
|
||||
|
@ -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.
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user