I am practicing Spring Boot automatic deployment using Travis CI
, AWS S3
, and AWS CodeDeploy
. Currently, if I do git push
, automatic deployment is in progress, but the following problem occurs.
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8080 was already in use.
Action:
Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.
So, I used the following command to check the process using port 8080.
sudo lsof -i TCP:8080
The user resulted in ec2-user
. If I kill ec2-user
with a kill pid to use port 8080, the server cannot be used. How to solve it?
hooks:
ApplicationStart:
- location: deploy.sh
timeout: 60
runas: ec2-user
#!/bin/bash
REPOSITORY=/home/ec2-user/app/travis
PROJECT_NAME=springboot-test
echo "> Copy Build File"
cp $REPOSITORY/zip/*.jar $REPOSITORY/
echo "> confirm current application pid"
CURRENT_PID=$(pgrep -fl $PROJECT_NAME | grep jar | awk '{print $1}')
echo "> pid: $CURRENT_PID"
if [ -z "$CURRENT_PID" ]; then
echo "> No application"
else
echo "> kill -15 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi
echo "> Deploy new application"
JAR_NAME=$(ls -tr $REPOSITORY/*.jar | tail -n 1)
echo "> JAR Name: $JAR_NAME"
echo "> Add +x in $JAR_NAME"
chmod +x $JAR_NAME
echo "> run $JAR_NAME"
nohup java -jar \
-Dspring.config.location=/home/ec2-user/app/application.yml \
-Dspring.profiles.active=real \
$JAR_NAME > $REPOSITORY/nohup.out 2>&1 &
You should add ApplicationStop hook into your appspec.yml
. The hook is executed first, and you should define it so that it stops your web server.