Skip to content

Commit

Permalink
chore: 생명 주기에 따라 스크립트 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
yujung7768903 committed Oct 13, 2024
1 parent ef1e66c commit 709ec5e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
17 changes: 10 additions & 7 deletions appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ permissions:
- file

hooks:
ApplicationStop:
- location: scripts/stop_was.sh
timeout: 60
runas: ec2-user
# JAVA_HOME과 PATH 설정을 명시적으로 로드
AfterInstall:
- location: /etc/profile.d/jdk.sh
timeout: 60
runas: root
ApplicationStart:
- location: scripts/run_new_was.sh
timeout: 60
runas: ec2-user
# - location: scripts/health_check.sh
# timeout: 60
# runas: ec2-user
# - location: scripts/switch.sh
# timeout: 60
# runas: ec2-user
runas: ec2-user
23 changes: 0 additions & 23 deletions scripts/run_new_was.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

#!/bin/bash

# JAVA_HOME과 PATH 설정을 명시적으로 로드
#if [ -f /etc/profile.d/jdk.sh ]; then
# source /etc/profile.d/jdk.sh
#fi

echo "start run_new_was"
echo "current user: $USER"
echo "JAVA_HOME: $JAVA_HOME"
Expand All @@ -15,26 +10,8 @@ shopt -q login_shell && echo "Login shell" || echo "Non-login shell"
PROJECT_ROOT="/home/ec2-user/backend"
JAR_FILE="$PROJECT_ROOT/build/libs/backend-0.0.1-SNAPSHOT.jar"

#CURRENT_PORT=$(cat /home/ec2-user/service_url.inc | grep -Po '[0-9]+' | tail -1)
TARGET_PORT=8080

#echo "> Current port of running WAS is ${CURRENT_PORT}."
#
#if [ ${CURRENT_PORT} -eq 8081 ]; then
# TARGET_PORT=8082
#elif [ ${CURRENT_PORT} -eq 8082 ]; then
# TARGET_PORT=8081
#else
# echo "> No WAS is connected to nginx"
#fi

TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+')

if [ ! -z ${TARGET_PID} ]; then
echo "> Kill WAS running at ${TARGET_PORT}."
sudo kill ${TARGET_PID}
fi

nohup java -jar -Dspring.profiles.active=prod -Dserver.port=${TARGET_PORT} ${JAR_FILE} > /home/ec2-user/nohup.out 2>&1 &
echo "> Now new WAS runs at ${TARGET_PORT}."
exit 0
11 changes: 11 additions & 0 deletions scripts/stop_was.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# stop_was.sh

#!/bin/bash
TARGET_PORT=8080

TARGET_PID=$(lsof -Fp -i TCP:${TARGET_PORT} | grep -Po 'p[0-9]+' | grep -Po '[0-9]+')

if [ ! -z ${TARGET_PID} ]; then
echo "> Kill WAS running at ${TARGET_PORT}."
sudo kill ${TARGET_PID}
fi

0 comments on commit 709ec5e

Please sign in to comment.