value=0
value2=0
echo > /dev/tcp/127.0.0.1/xxx2
value=`echo $?`
echo > /dev/tcp/127.0.0.1/xxx1
value2=`echo $?`
echo "xxx2오픈상황:${value}"
echo "xxx1오픈상황:${value2}"
timestamp=`date +%Y%m%d%H%M`
echo "$timestamp"
cd /home/ec2-user/jenkins
mv xxx.jar ${timestamp}.jar
mv ${timestamp}.jar /home/ec2-user/
cd /home/ec2-user
port=0;
upport=0;
if [ ${value} -eq 0 ]
then
echo 'xxx1시작'
sed -i 's/xxx2/xxx1/g' /etc/nginx/nginx.conf
sudo nohup java -javaagent:/home/ec2-user/scouter/agent.java/scouter.agent.jar -Dscouter.config=/home/ec2-user/scouter/agent.java/conf/scouter.conf -Dobj_name=home -jar -Dspring.profiles.active=test ${timestamp}.jar &
port=xxx2
upport=xxx1
else
sed -i 's/xxx1/xxx2/g' /etc/nginx/nginx.conf
echo 'xxx2시작'
sudo nohup java -javaagent:/home/ec2-user/scouter/agent.java/scouter.agent.jar -Dscouter.config=/home/ec2-user/scouter/agent.java/conf/scouter2.conf -Dobj_name=home2 -jar -Dspring.profiles.active=test2 ${timestamp}.jar &
port=xxx1
upport=xxx2
fi
stop=1
while :
do
echo > /dev/tcp/127.0.0.1/$upport;
stop=`echo $?`;
echo "실행중";
if [ $stop -eq 0 ]; then
break;
else
echo "아직실행되지 않았습니다 10초sleep";
sleep 10
fi
done
echo '실행완료';
sudo nginx -s reload
echo "종료할 포트:${port}"
result_value=$(netstat -nap 2>/dev/null | grep ${port} | awk '{print $7}')
number_value=${#result_value}
if [ $number_value == 0 ]; then
echo '해당포트가 미사용중으로 이미 종료되었습니다..'
else
echo '종료를 시작합니다.'
pid_val=${result_value%%'/'*}
echo "종료 예정포트 ${pid_val}"
sudo kill -9 $pid_val
echo `종료포트결과,sudo lsof -i :${port}`
fi
'aws > EC2' 카테고리의 다른 글
sudoers 파일 수정 (0) | 2022.12.12 |
---|---|
ec2 linux nmon crontab 자동 수집 (0) | 2022.12.09 |
aws linux 기본 세팅하기(java,nginx,scouter,nmon,jenkins) (0) | 2022.11.25 |
EC2+Springboot+Amazon ElastiCache(redis) (0) | 2022.09.01 |
EC2 FileZila 연동하기 (0) | 2022.08.25 |