upgrade |
|
|---|---|
|
版权所有 2015 Hewlett-Packard Development Company, L.P. 根据 Apache 许可证 2.0 版(“许可证”)授权;除非符合许可证,否则您不得使用此文件。您可以从以下位置获取许可证的副本: https://apache.org/licenses/LICENSE-2.0 除非适用法律要求或书面同意,根据许可证分发的软件以“原样”基础分发,不提供任何形式的保证或条件,无论是明示的还是暗示的。请参阅许可证以了解管理许可证下权限和限制的具体语言。 # DIVIDER #!/bin/bash # DIVIDER export DATABASES_TO_SAVE=${DATABASES_TO_SAVE:-} # DIVIDER function save_mysql_dbs { local release=$1 local dir=$2 # DIVIDER local mysql_pass=$( set +o xtrace && source $dir/stackrc && echo $MYSQL_PASSWORD) local database_user=$( set +o xtrace && source $dir/stackrc && echo ${DATABASE_USER:-root}) db_names=( $(mysql -u$database_user -p$mysql_pass -Bse "show databases;") ) for db in $DATABASES_TO_SAVE; do for db_found in "${db_names[@]}"; do if [[ "$db" == "$db_found" ]]; then echo "Saving database :" $db timeout 120 mysqldump --skip-lock-tables -u$database_user -p$mysql_pass $db >$SAVE_DIR/$db.sql.$release break fi done done } # DIVIDER function register_db_to_save { for db in $@; do DATABASES_TO_SAVE+=" $db" done } # DIVIDER function upgrade_service { local local_service=$1 local plugin_dir=${PLUGIN_DIR[$local_service]} if [[ -n "$plugin_dir" ]]; then echo_summary "Upgrading $local_service..." TOP_DIR=$TARGET_DEVSTACK_DIR $plugin_dir/upgrade.sh || die $LINENO "Failure in $plugin_dir/upgrade.sh" else echo_summary "Upgrading $local_service... (legacy mode)" $GRENADE_DIR/upgrade-$local_service || die $LINENO "Failure in upgrade-$local_service" fi } # DIVIDER function upgrade_project { # DIVIDER project=$1 base_dir=$2 base_branch=$3 target_branch=$4 if [[ "$base_branch" == "$target_branch" ]]; then direction="within" else direction="from" fi upgrade_dir=$(get_release_name_from_branch $base_branch) upgrade_file=${base_dir}/${direction}"-"${upgrade_dir}/"upgrade-"${project} if [[ -e ${upgrade_file} ]]; then source ${upgrade_file} && configure_${project}_upgrade else echo "Warning: No new configurations were found for OpenStack $project." echo "If your patch fails during the upgrade this may be the cause." fi } # DIVIDER function register_project_for_upgrade { local project=$1 # DIVIDER local settings_file=$(caller | awk '{print $2}') local dir=$(dirname $settings_file) UPGRADE_PROJECTS+=" $project" PLUGIN_DIR[$project]=$dir } function is_service_running { local name="$1" local exitcode=0 if $SYSTEMCTL is-enabled "devstack@$name" --no-pager; then $SYSTEMCTL status "devstack@$name" --no-pager exitcode=$? # DIVIDER else deprecated "Using the process name with ps for service status is deprecated, please update to use the systemd unit name" ps auxw | grep -v grep | grep -v shutdown.sh | grep -v upgrade.sh | grep -e "${name}" exitcode=$? fi return $exitcode } # DIVIDER # DIVIDER function ensure_services_stopped { local wait_for=$SERVICE_TIMEOUT local still_running="" while [ $wait_for -gt 0 ]; do still_running="" local service="" for service in "$@"; do if is_service_running "${service}"; then still_running+=" $service" fi done if [[ -n "$still_running" ]]; then echo "The following services are still running: $still_running... sleeping and trying again" sleep 1 else break fi wait_for=$[$wait_for - 1] done if [[ -n "$still_running" ]]; then # DIVIDER ps auxw ss -p -t -o state established die $LINENO "The following services are still running: $still_running" fi } # DIVIDER function ensure_services_started { local wait_for=$SERVICE_TIMEOUT while [ $wait_for -gt 0 ]; do not_running="" local service="" for service in "$@"; do if ! is_service_running "${service}"; then not_running+=" $service" fi done if [[ -n "$not_running" ]]; then echo "The following services are not running: $not_running... sleeping and trying again" sleep 1 else break fi wait_for=$[$wait_for - 1] done if [[ -n "$not_running" ]]; then die $LINENO "The following services did not appear to start: $not_running" fi } function ensure_logs_exist { local logname="" local not_found="" for logname in $@; do local log=${SCREEN_LOGDIR}/screen-$logname.log if [[ ! -e $log ]]; then not_found+=" $log" fi done if [[ -n "$not_found" ]]; then die $LINENO "The following service logs were not found: $not_found" fi } # DIVIDER | |
|
以下变量假定由某些函数定义
| |
|
save_data | |
|
从旧的配置文件中获取mysql密码 | |
|
注册一个我们应该保存的数据库 | |
|
升级 $UPGRADE_PROJECTS 中列出的服务。 | |
|
如果项目存在,此函数会触发每个项目的升级过程,否则会显示一条关于缺少此文件的警告消息。 | |
|
注意(maurosr):理想情况下,在发布后立即进行新的升级测试时,不需要新的配置,因此我们可以继续进行,而无需来自<release>目录。 这也很有用,因为 d-g 和 grenade 之间存在交叉依赖关系,当启用 grenade 在一对新发布版本之间运行升级时。 | |
|
外部插件的注册接口 | |
|
使用调用者,以便我们知道调用此函数的文件的位置,并从中推导出插件目录的位置。 | |
|
如果未找到单元,则回退到 ps 方法 | |
|
处理服务检查的函数 | |
|
ensure_services_stopped 等待服务停止,最多等待 10 秒,因为有时服务需要一段时间才能关闭。 | |
|
TODO(sdague):规避措施,因为 worlddump 显然配置错误 | |
|
处理服务检查的函数 | |