1、现阶段所有的 Rancher 环境变量 皆无默认值,因此,皆必须在 Rancher 环境变量中明确设置,如图1
2、之前的环境变量的配置文件,如果未设置环境变量:CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX,则设置其默认值为:CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX,即其值为其键名
#!/bin/bash # 记录日志 DIR=/config/init # 配置文件 DEV_COMMON_CONFIG_MAIN_LOCAL_PATH=/sobey/www/channel-pub-api/environments/dev/common/config/main-local.php function DEV_COMMON_CONFIG_MAIN_LOCAL_PATH_exsit() { env | grep "CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX" || export CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX="CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX" sed -i "s#CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX#$CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX#g" $DEV_COMMON_CONFIG_MAIN_LOCAL_PATH echo "CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX replace $CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX -> $DEV_COMMON_CONFIG_MAIN_LOCAL_PATH" echo "CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX replace $CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX -> $DEV_COMMON_CONFIG_MAIN_LOCAL_PATH" >> $DIR/change.log } # 判断文件是否存在 ls $DEV_COMMON_CONFIG_MAIN_LOCAL_PATH >/dev/null 2>&1 && DEV_COMMON_CONFIG_MAIN_LOCAL_PATH_exsit || echo "$DEV_COMMON_CONFIG_MAIN_LOCAL_PATH 不存在" >> $DIR/change.log
3、现在的环境变量的配置文件,如果未设置环境变量:CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX,则设置其默认值为:cpa_,且删除(设置其默认值为:CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX,即其值为其键名)
#!/bin/bash # 记录日志 DIR=/config/init # 配置文件 DEV_COMMON_CONFIG_MAIN_LOCAL_PATH=/sobey/www/channel-pub-api/environments/dev/common/config/main-local.php # Rancher 环境变量(已设置默认值,可无需设置) env | grep "CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX" || export CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX="cpa_" function DEV_COMMON_CONFIG_MAIN_LOCAL_PATH_exsit() { sed -i "s#CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX#$CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX#g" $DEV_COMMON_CONFIG_MAIN_LOCAL_PATH echo "CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX replace $CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX -> $DEV_COMMON_CONFIG_MAIN_LOCAL_PATH" echo "CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX replace $CHANNEL_PUB_API_CFG_DB_TABLE_PREFIX -> $DEV_COMMON_CONFIG_MAIN_LOCAL_PATH" >> $DIR/change.log } # 判断文件是否存在 ls $DEV_COMMON_CONFIG_MAIN_LOCAL_PATH >/dev/null 2>&1 && DEV_COMMON_CONFIG_MAIN_LOCAL_PATH_exsit || echo "$DEV_COMMON_CONFIG_MAIN_LOCAL_PATH 不存在" >> $DIR/change.log
4、调整之后的结果,Rancher 环境变量(未设置默认值,必须设置) 49,Rancher 环境变量(已设置默认值,可无需设置) 54,如图2
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/181304.html