wsx

Posted storm1018

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wsx相关的知识,希望对你有一定的参考价值。

#! /bin/sh
_DIRNAME=$(dirname $0)
_CUR_PATH=$(cd ${_DIRNAME}; pwd)
. ${_CUR_PATH}/docker-init.conf
MATEINFO_HOME=/opt/mateinfo
MATEINFO_LOG_PATH=/opt/mateinfo/logs

# 替换文件中某个字符串
# 参数1:原始字符
# 参数2:目标字符 
# 参数3:文件路径
function _replace_param()
{
    local src_word=$1
    local dst_word=$2
    local file_path=$3
    if [ $(echo ${src_word} | grep "#" | wc -l) -gt 0 -o $(echo ${dst_word} | grep "#" | wc -l) -gt 0 ]
    then
    {
        if [ $(echo ${src_word} | grep "/" | wc -l) -gt 0 -o $(echo ${dst_word} | grep "/" | wc -l) -gt 0 ]
        then
        {
            sed -i "s+${src_word}+${dst_word}+g" ${file_path}
        }
        else
        {
            sed -i "s/${src_word}/${dst_word}/g" ${file_path}
        }
        fi
    }
    else
    {
        sed -i "s#${src_word}#${dst_word}#g" ${file_path}
    }
    fi
}

# 安装固定格式打印日志到控制台
# 默认模块名为脚本名称,可声明_MODULE_NAME变量自行指定
# 参数1:日志内容
function _print_log()
{
    local module_name=$0
    local curr_user=$(whoami | awk {print $1})
    local curr_user_ip=$(who am i|awk -F  {print $NF}|grep -o -E "[0-9\.]*")
    if [ ! -z ${_MODULE_NAME} ]
    then
        module_name=${_MODULE_NAME}
    fi
    msg="$1\n"
    printf "[`date ‘+%Y-%m-%d %H:%M:%S‘`]-[${curr_user}]-[${curr_user_ip}]-[${module_name}] ${msg}";
}

# 检查当前用户是否为xx
# 参数1:需要的用户名
function _check_user
{
    local user=${1};
    if [ "$(whoami | awk ‘{print $1}‘)" != "${user}" ]
    then
        _print_log "Please run this script with the user \"${user}\", run \"su - ${user}\" to switch the user."
        exit 1;
    fi
}

function main()
{
    _check_user "root"
    
    _print_log "replace placeholder in properties"
    _replace_param "@{SSO_PUBLIC_ADDRESS}" ${SSO_PUBLIC_ADDRESS} ${MATEINFO_HOME}/conf/ssoconfig.properties
    _replace_param "@{SSO_PRIVATE_ADDRESS}" ${SSO_PRIVATE_ADDRESS} ${MATEINFO_HOME}/conf/ssoconfig.properties
    _replace_param "@{MATEINFO_DB_IP}" ${MATEINFO_DB_IP} ${MATEINFO_HOME}/app/conf/catalina.properties
    _replace_param "@{MATEINFO_DB_PORT}" ${MATEINFO_DB_PORT} ${MATEINFO_HOME}/app/conf/catalina.properties
    _replace_param "@{MATEINFO_DB_IP}" ${MATEINFO_DB_IP} ${MATEINFO_HOME}/app/conf/catalina.properties
    _replace_param "@{MATEINFO_DB_NAME}" ${MATEINFO_DB_NAME} ${MATEINFO_HOME}/app/conf/catalina.properties
    _replace_param "@{MATEINFO_DB_USERNAME}" ${MATEINFO_DB_USERNAME} ${MATEINFO_HOME}/app/conf/catalina.properties
    _replace_param "@{MATEINFO_DB_PASSWORD_ENC}" ${MATEINFO_DB_PASSWORD_ENC} ${MATEINFO_HOME}/app/conf/catalina.properties
    _replace_param "@{REDIS_IP}" ${REDIS_IP} ${MATEINFO_HOME}/app/conf/catalina.properties
    _replace_param "@{REDIS_PORT}" ${REDIS_PORT} ${MATEINFO_HOME}/app/conf/catalina.properties
    _replace_param "@{REDIS_PASSWORD_ENC}" "" ${MATEINFO_HOME}/app/conf/catalina.properties
    _replace_param "@{KEYSTORE_PASSWORD_ENC}" ${KEYSTORE_PASSWORD_ENC} ${MATEINFO_HOME}/app/conf/catalina.properties
    _replace_param "@{ZOOKEEPER_ADDRESS}" ${ZOOKEEPER_ADDRESS} ${MATEINFO_HOME}/conf/mateinfo.properties
    _replace_param "@{PLATFORM_VERSION}" ${PLATFORM_VERSION} ${MATEINFO_HOME}/conf/mateinfo.properties
    
    _print_log "restart app"
    su - mateinfo -c "sh /opt/mateinfo/bin/mateinfo-admin.sh restart"
}

mkdir -p ${MATEINFO_LOG_PATH}
echo "" > ${MATEINFO_LOG_PATH}/docker-init.log
main [email protected] 2>&1 | tee -a ${MATEINFO_LOG_PATH}/docker-init.log

 

以上是关于wsx的主要内容,如果未能解决你的问题,请参考以下文章

微信小程序代码片段

VSCode自定义代码片段——CSS选择器

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

片段和活动之间的核心区别是啥?哪些代码可以写成片段?

递归该怎么写

VSCode自定义代码片段——.vue文件的模板