#!/bin/bash

# 启动tomcat
/opt/tomcat8/bin/startup.sh

# 等待解压war包完毕
while [ ! -e "/opt/tomcat8/webapps/ROOT" ]; do
  sleep 3
done

# 根据环境变量替换缓存地址
sed -i "s/cacheaddr=\"..*\"/cacheaddr=\"$CACHE_ACC_ADDR\"/g" /opt/tomcat8/webapps/ROOT/WEB-INF/cgi/head.sh
sed -i "s/10.10.10.27/$CACHE_ACC_ADDR/g" /opt/tomcat8/webapps/ROOT/WEB-INF/cgi/doLogin.sh
sed -i "s/10.10.10.27/$CACHE_ACC_ADDR/g" /opt/tomcat8/webapps/ROOT/WEB-INF/cgi/doLogout.sh

# 根据环境变量替换读数据库地址
sed -i "s/rmysqladdr=\"..*\"/rmysqladdr=\"$RMYSQL_ACC_ADDR\"/g" /opt/tomcat8/webapps/ROOT/WEB-INF/cgi/head.sh

# 根据环境变量替换写数据库地址
sed -i "s/wmysqladdr=\"..*\"/wmysqladdr=\"$WMYSQL_ACC_ADDR\"/g" /opt/tomcat8/webapps/ROOT/WEB-INF/cgi/head.sh

# 占用终端不退出
tail -f /opt/tomcat8/logs/catalina.out
