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

在 Rancher 中升级容器,同一个镜像地址,环境变量有容器已被替换,有容器未被替换的分析解决

查看环境变量未被替换的容器的日志。无相应环境变量已被替换的提示。且报错:Invalid Date Invalid Date grabbing logs: EOF。即无效的日期 获取日志:EOF。
1、进入环境变量已被替换的容器,某个配置文件,符合预期。如图1
进入环境变量已被替换的容器,某个配置文件,符合预期。
图1
2、进入环境变量未被替换的容器,某个配置文件,不符合预期。如图2
进入环境变量未被替换的容器,某个配置文件,不符合预期。
图2
3、查看环境变量已被替换的容器的日志。有相应环境变量已被替换的提示。如图3
查看环境变量已被替换的容器的日志。有相应环境变量已被替换的提示。
图3


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、查看环境变量未被替换的容器的日志。无相应环境变量已被替换的提示。且报错:Invalid Date Invalid Date grabbing logs: EOF。即无效的日期 获取日志:EOF。如图4
查看环境变量未被替换的容器的日志。无相应环境变量已被替换的提示。且报错:Invalid Date Invalid Date grabbing logs: EOF。即无效的日期 获取日志:EOF。
图4


Invalid Date Invalid Date grabbing logs: EOF


5、查看环境变量未被替换的容器,升级(Upgrade) – 命令(Command) – 入口(Entry Point):/bin/bash。而查看环境变量已被替换的容器,其值为空。其作用为配置容器启动后执行的命令。如图5
查看环境变量未被替换的容器,升级(Upgrade) - 命令(Command) - 入口(Entry Point):/bin/bash。而查看环境变量已被替换的容器,其值为空。其作用为配置容器启动后执行的命令。
图5
6、编辑环境变量未被替换的容器,升级(Upgrade) – 命令(Command) – 入口(Entry Point):。设置其值为空。重新升级。容器的日志未再报错,环境变量已被替换。此时,容器启动后执行的命令脚本为:/config/bootstrap.sh。此脚本中包含环境变量替换的实现。


#!/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+ 年经验的 PHP / Go 后端工程师,长期关注已有系统维护、Bug 修复、性能优化、服务器排查、WordPress 网站维护和小功能迭代。

如果你的项目遇到以下情况,可以先从一次小问题排查开始合作:

  • ✅ PHP / Laravel / Yii2 老项目无人维护
  • ✅ Go / Gin 后端接口需要排查或优化
  • ✅ WordPress 网站访问慢、报错或插件冲突
  • ✅ Nginx / MySQL / Redis / Linux 服务器异常
  • ✅ CDN / Cloudflare / DNS / HTTPS 配置问题
  • ✅ 需要长期远程技术支持或兼职维护

更多介绍请查看:关于我 & 合作

微信:13980074657
邮箱:shuijingwanwq@gmail.com
Telegram:@shuijingwan
GitHub:https://github.com/shuijingwan

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理