You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.8 KiB
94 lines
3.8 KiB
#!/bin/bash
|
|
source /data/anhei/docker/3rd/feishu/pusher.sh
|
|
IMAGES_VERSION=10.100.0.5:8888/library/anhei_basics:1.4
|
|
#容器编号:1、2、3
|
|
CONTAINER_CODE=$1
|
|
#分支:branches/dev/newpet
|
|
BRANCH_NAME=$2
|
|
#数据源 IP地址
|
|
MYSQL_HOST=$3
|
|
#jenkins 构建好的文件的路径(或者地址)
|
|
PACKAGE_PATH=/data/wwwroot/release_package/${BRANCH_NAME}_anhei/Linux/
|
|
cd ${PACKAGE_PATH}
|
|
FILE_NAME=$(ls -t | head -n 1)
|
|
FILE_PATH=${PACKAGE_PATH}${FILE_NAME}
|
|
|
|
##挂载路径
|
|
MOUNT_PATH=/data/mmogrun/publish/
|
|
OUT_MOUNT_PATH=/data/mmogrun/${CONTAINER_CODE}"/" ##外部挂载目录
|
|
|
|
#sql 文件挂载目录
|
|
MOUNT_SQL_PATH=/data/mysql_backup/
|
|
|
|
OUT_MOUNT_SQL_PATH=${MOUNT_SQL_PATH} ##外部挂载目录
|
|
|
|
WEB_PATH=/data/wwwroot/oss
|
|
if [ -d "${OUT_MOUNT_PATH}" ]; then
|
|
echo "文件夹存在.容器编号重复"
|
|
exit 1
|
|
fi
|
|
#拷贝执行文件到对应的挂载目录下
|
|
mkdir -p "${OUT_MOUNT_PATH}"
|
|
cp -rf "${FILE_PATH}" "${OUT_MOUNT_PATH}"
|
|
|
|
#基础bin
|
|
BASE_BIN_PATH=/data/mmogrun/${CONTAINER_CODE}/publish/bin
|
|
mkdir -p "${BASE_BIN_PATH}"
|
|
tar -zxvf /tmp/bin.tgz -C /data/mmogrun/"${CONTAINER_CODE}"/
|
|
|
|
#映射端口:(容器编号-1)*10+port
|
|
|
|
NUM=`expr ${CONTAINER_CODE} - 1`
|
|
TEMP_CODE=`expr ${NUM} \* 10`
|
|
GM_PORT=`expr 6318 + ${TEMP_CODE}` #GM 端口
|
|
VERSION_PORT=`expr 9601 + ${TEMP_CODE} ` #版本服
|
|
GAME_PORT=`expr 9720 + ${TEMP_CODE}` #游戏服
|
|
REALM_GATE_PORT_1=`expr 9721 + ${TEMP_CODE}` #realm_gate_1网关
|
|
REALM_GATE_PORT_2=`expr 9722 + ${TEMP_CODE}` #realm_gate_2网关
|
|
CHAT_GATE_PORT=`expr 9820 + ${TEMP_CODE}` #聊天网关
|
|
#6318 9601 9710 9711 9712 9810
|
|
#6328 9621 9720 9721 9722 9820
|
|
#6338 9631 9730 9731 9732 9830
|
|
|
|
echo "Port Info GAME_PORT=${GAME_PORT},VERSION_PORT=${VERSION_PORT},GM_PORT=${GM_PORT},CHAT_GATE_PORT=${CHAT_GATE_PORT},REALM_GATE_PORT_1=${REALM_GATE_PORT_1},REALM_GATE_PORT_2=${REALM_GATE_PORT_2}"
|
|
|
|
cp /data/anhei/docker/cmd.sh "${OUT_MOUNT_PATH}"
|
|
# shellcheck disable=SC2164
|
|
cd "${OUT_MOUNT_PATH}"
|
|
#FILE_NAME=$(basename "${FILE_PATH}")
|
|
tar -xvf "${FILE_NAME}"
|
|
# shellcheck disable=SC2140
|
|
|
|
docker run -m 4g -it -d --privileged=true --name 'docker_game_'"${CONTAINER_CODE}"'_server' -v "${OUT_MOUNT_PATH}publish":"${MOUNT_PATH}" -v ${MOUNT_SQL_PATH}:${MOUNT_SQL_PATH} -p "${GAME_PORT}":9720 -p "${VERSION_PORT}":9601 -p "${CHAT_GATE_PORT}":9820 -p "${REALM_GATE_PORT_1}":9721 -p "${REALM_GATE_PORT_2}":9722 -p "${GM_PORT}":56318 ${IMAGES_VERSION} /bin/bash >maintainer.pid
|
|
PID=$(cat maintainer.pid)
|
|
echo "${PID}"
|
|
docker ps |grep "${GAME_PORT}"
|
|
# shellcheck disable=SC2086
|
|
|
|
|
|
#写入env文件中,方便后面查看
|
|
|
|
MACHINE_HOST_DOMAIN="101.42.52.13" #宿主机外网地址
|
|
|
|
ENV_FILE=${OUT_MOUNT_PATH}env.env
|
|
echo 'docker_'"${CONTAINER_CODE}=${PID}" >> ${ENV_FILE}
|
|
echo export CONTAINER_CODE=${CONTAINER_CODE} >> ${ENV_FILE}
|
|
echo export GAME_PORT="${GAME_PORT}" >> ${ENV_FILE}
|
|
echo export VERSION_PORT="${VERSION_PORT}" >> ${ENV_FILE}
|
|
echo export CHAT_GATE_PORT="${CHAT_GATE_PORT}" >> ${ENV_FILE}
|
|
echo export REALM_GATE_PORT_1="${REALM_GATE_PORT_1}" >> ${ENV_FILE}
|
|
echo export REALM_GATE_PORT_2="${REALM_GATE_PORT_2}" >> ${ENV_FILE}
|
|
echo export MYSQL_HOST="${MYSQL_HOST}" >> ${ENV_FILE}
|
|
echo export MACHINE_HOST_DOMAIN="${MACHINE_HOST_DOMAIN}" >> ${ENV_FILE}
|
|
docker cp /data/anhei/docker/3rd "${PID}":/
|
|
docker cp ${ENV_FILE} "${PID}":/3rd/ #方便容器内部也需要
|
|
|
|
docker cp /tmp/web.zip "${PID}":${WEB_PATH}/
|
|
|
|
docker exec "${PID}" /3rd/init.sh "${CONTAINER_CODE}"
|
|
#feiShu_Pusher "${CONTAINER_CODE}" "创建容器成功:${PID}"
|
|
echo "Running Docker ${CONTAINER_CODE} successfully"
|
|
|
|
|
|
curl -X POST http://127.0.0.1:8088/server/submit -H 'Content-Type: application/json' -d '{"order":"'${CONTAINER_CODE}'","branch":"'${BRANCH_NAME}'","name":"docker_'${CONTAINER_CODE}'","code":"'${CONTAINER_CODE}'","ip":"'${MACHINE_HOST_DOMAIN}'","game_port":"'${GAME_PORT}'","version_port":"'${VERSION_PORT}'","g_gate_port":"'${REALM_GATE_PORT_1}'","c_gate_port":"'${CHAT_GATE_PORT}'","gm_port":"'${GM_PORT}'"}'
|
|
|