gpt4 book ai didi

java - 通过 teamcity 完成部署时日志卡住

转载 作者:太空宇宙 更新时间:2023-11-04 11:55:15 24 4
gpt4 key购买 nike

最近我们从手动流程迁移到 Teamcity 部署。我们的是 linux 服务器上的 java 应用程序。每当通过 Teamcity 完成部署时,日志都会卡住,即在关闭日志消息后,日志中不会打印任何其他内容。然后我们在服务器上运行手动停止和启动脚本来运行日志。看起来 Teamcity 以某种方式锁定了日志文件并且没有释放它。

如何克服?

在Teamcity中,部署步骤定义如下:

REMOTE_PATH="/opt/app/$ARTIFACT/releases/teamcity"

cd $TEAMCITY_REPO_HOME/$ARTIFACT/build/libs

echo "Uploading artifact"
ssh $UAT_HOST -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "mkdir -p $REMOTE_PATH"
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $ARTIFACT.jar $UAT_HOST:$REMOTE_PATH

echo "Stopping service"
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $UAT_HOST "sh /opt/app/$ARTIFACT/stop.sh"

sleep 3s

echo "Copying new artifact"
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $UAT_HOST "cp $REMOTE_PATH/$ARTIFACT.jar /opt/app/$ARTIFACT"

sleep 6s

echo "Starting service"
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $UAT_HOST "sh /opt/app/$ARTIFACT/start.sh"

最佳答案

根据 Andy Dufresne 的上述评论,我创建了一个部署脚本,如下所示:这个单一脚本停止服务器,备份当前工件,复制新构建,然后执行启动脚本以启动服务器。

#!/bin/bash
#check for correct number of arguments
if [ "$#" -ne 1 ]; then
echo "Incorrect number of arguments, exiting..."
exit 1
fi

ARTIFACT=$1

cd "/opt/app/$ARTIFACT"
echo $(pwd)

echo "Stopping service"
bash stop.sh

sleep 3s

echo "Tagging artifact with release"
cp "releases/teamcity/$ARTIFACT.jar" "releases/teamcity/$ARTIFACT`date +'_%y_%m_%d'`.jar"

echo "Deleting old releases"
cd "releases/teamcity" && \
ls | grep -v '/$' | head -n -6 | xargs -d '\n' -r rm -- && \
cd "/opt/app/$ARTIFACT" && \
ls -l "releases/teamcity"

echo "Copying new artifact"
cp "releases/teamcity/$ARTIFACT.jar" .

echo "Starting service"
bash start.sh

sleep 2s

此脚本在其构建步骤中从 team-city 调用(之前停止服务器、复制工件和启动服务器都是由 teamcity 明确完成的,如问题中所述。)现在 teamcity 构建步骤看起来像下面那样简洁并且按预期工作(这很重要!!!):

REMOTE_PATH="/opt/app/$ARTIFACT/releases/teamcity"

cd $TEAMCITY_REPO_HOME/$ARTIFACT/build/libs

echo "Uploading artifact"
ssh -o "StrictHostKeyChecking=no" "$UAT_HOST" "mkdir -p $REMOTE_PATH"
scp -o "StrictHostKeyChecking=no" "$ARTIFACT.jar" "$UAT_HOST:$REMOTE_PATH"

echo "Deploying artifact"
ssh -o "StrictHostKeyChecking=no" "$UAT_HOST" "sh /opt/app/$ARTIFACT/deploy.sh $ARTIFACT"

关于java - 通过 teamcity 完成部署时日志卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54596013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com