没有不值得去解决的问题,也没有不值得去学习的技术!

Analyzing and Resolving Unreplaced Containers After Upgrading With the Same Image Address in Rancher

Checking the logs of the container where the environment variables had not been replaced. There are no prompts indicating that the corresponding environment variables have been replaced. And it reports an error: Invalid Date Invalid Date grabbing logs: EOF. That is, invalid date grabbing logs: EOF.

1. I entered the container where the environment variables had been replaced, and a certain configuration file met expectations. See Figure 1.

Entering the container where the environment variables had been replaced, a certain configuration file met expectations.
Figure 1

2. I entered the container where the environment variables had not been replaced, and a certain configuration file did not meet expectations. See Figure 2.

Entering the container where the environment variables had not been replaced, a certain configuration file did not meet expectations.
Figure 2

3. I checked the logs of the container where the environment variables had been replaced. There are prompts indicating that the corresponding environment variables have been replaced. See Figure 3.

Checking the logs of the container where the environment variables had been replaced. There are prompts indicating that the corresponding environment variables have been replaced.
Figure 3
Plaintext
2020/8/11 下午3:03:11 PCS_CFG_NGINX_SERVER_NAME=pcs.wjtest.chinamcloud.cn
2020/8/11 下午3:03:11 PCS_CFG_API_HOST_INFO=http://pcsapi.wjtest.chinamcloud.cn
2020/8/11 下午3:03:11 PCS_CFG_API_BASE_URL=/v1
2020/8/11 下午3:03:11 PCS_CFG_CALLBACK_LOGIN=http://cmcgroup.wjtest.chinamcloud.cn/login/index?call_back=http://pcs.wjtest.chinamcloud.cn/#/topic/add
2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_URL=https://cmcconsole.wjtest.chinamcloud.cn
2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_HEADER_LEFT_CSS=/cmc/cmc_header_left.css
2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_HEADER_LEFT_JS=/cmc/cmc_header_left.js
2020/8/11 下午3:03:11 PCS_CFG_YS_FLAG=申请任务
2020/8/11 下午3:03:11 PCS_CFG_BQ_FLAG=0
2020/8/11 下午3:03:11 PCS_CFG_NGINX_SERVER_NAME replace pcs.wjtest.chinamcloud.cn -> /etc/nginx/conf.d/pcs.conf
2020/8/11 下午3:03:11 PCS_CFG_API_HOST_INFO replace http://pcsapi.wjtest.chinamcloud.cn -> /etc/nginx/conf.d/pcs.conf
2020/8/11 下午3:03:11 PCS_CFG_API_BASE_URL replace /v1 -> /etc/nginx/conf.d/pcs.conf
2020/8/11 下午3:03:11 sed: -e expression #1, char 120: unknown option to `s'
2020/8/11 下午3:03:11 PCS_CFG_CALLBACK_LOGIN replace http://cmcgroup.wjtest.chinamcloud.cn/login/index?call_back=http://pcs.wjtest.chinamcloud.cn/#/topic/add -> /mcloud/www/pcs/build/config.js
2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_URL replace https://cmcconsole.wjtest.chinamcloud.cn -> /mcloud/www/pcs/build/config.js
2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_HEADER_LEFT_CSS replace /cmc/cmc_header_left.css -> /mcloud/www/pcs/build/config.js
2020/8/11 下午3:03:11 PCS_CFG_CMC_CONSOLE_HEADER_LEFT_JS replace /cmc/cmc_header_left.js -> /mcloud/www/pcs/build/config.js
2020/8/11 下午3:03:11 PCS_CFG_YS_FLAG replace 申请任务 -> /mcloud/www/pcs/build/config.js
2020/8/11 下午3:03:11 PCS_CFG_BQ_FLAG replace 0 -> /mcloud/www/pcs/build/config.js
2020/8/11 下午3:03:11 /config/init/cronlog.sh: line 4: LOG_NAME: unbound variable

4. I checked the logs of the container where the environment variables had not been replaced. There are no prompts indicating that the corresponding environment variables have been replaced. And it reports an error: Invalid Date Invalid Date grabbing logs: EOF. That is, invalid date grabbing logs: EOF. See Figure 4.

Checking the logs of the container where the environment variables had not been replaced. There are no prompts indicating that the corresponding environment variables have been replaced. And it reports an error: Invalid Date Invalid Date grabbing logs: EOF. That is, invalid date grabbing logs: EOF.
Figure 4
Plaintext

Invalid Date Invalid Date grabbing logs: EOF

5. I checked the container where the environment variables had not been replaced, under Upgrade – Command – Entry Point: /bin/bash. However, checking the container where the environment variables had been replaced, its value is empty. Its purpose is to configure the command executed after the container starts. See Figure 5.

Checking the container where the environment variables had not been replaced, under Upgrade - Command - Entry Point: /bin/bash. However, checking the container where the environment variables had been replaced, its value is empty. Its purpose is to configure the command executed after the container starts.
Figure 5

6. I edited the container where the environment variables had not been replaced, under Upgrade – Command – Entry Point:. I set its value to empty and upgraded again. The container logs no longer reported errors, and the environment variables had been replaced. At this point, the command script executed after the container starts is: /config/bootstrap.sh. This script contains the implementation of the environment variable replacement.

ShellScript

#!/bin/bash
localedef -i en_US -f UTF-8 en_US.UTF-8
set -e
set -u

# Supervisord default params
SUPERVISOR_PARAMS='-c /etc/supervisord.conf'


# Create directories for supervisor's UNIX socket and logs (which might be missing
# as container might start with /data mounted from another data-container).
mkdir -p /data/conf /data/run /data/logs
chmod 711 /data/conf /data/run /data/logs

if [ "$(ls /config/init/)" ]; then
  for init in /config/init/*.sh; do
    . $init
  done
fi


# We have TTY, so probably an interactive container...
if test -t 0; then
  # Run supervisord detached...
  supervisord $SUPERVISOR_PARAMS

  # Some command(s) has been passed to container? Execute them and exit.
  # No commands provided? Run bash.
  if [[ $@ ]]; then
    eval $@
  else
    export PS1='[\u@\h : \w]\$ '
    /bin/bash
  fi

# Detached mode? Run supervisord in foreground, which will stay until container is stopped.
else
  # If some extra params were passed, execute them before.
  # @TODO It is a bit confusing that the passed command runs *before* supervisord,
  #       while in interactive mode they run *after* supervisor.
  #       Not sure about that, but maybe when any command is passed to container,
  #       it should be executed *always* after supervisord? And when the command ends,
  #       container exits as well.
  if [[ $@ ]]; then
    eval $@
  fi
  supervisord -n $SUPERVISOR_PARAMS
fi

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系