APP_JAR_PATH="/home/webapp/${APP_NAME}.jar"
APP_PID_PATH="/home/webapp/${APP_NAME}.pid"
NEW_APP_JAR="/tmp/${APP_NAME}.jar"
APP_LOG_PATH="/home/webapp/${APP_NAME}.log"
if [ ! -f "${NEW_APP_JAR}" ]; then
echo "New application artifact not found!"
if [ -f "${APP_JAR_PATH}" ]; then
echo "Check current application artifact"
echo "Current application artifact not found!"
echo "Check new application artifact"
echo "Stopping the application..."
if [ -f "${APP_JAR_PATH}" ]; then
if curl -s -o /dev/null -X POST http://localhost:8080/actuator/shutdown; then
echo "Shutdown request sent successfully."
echo "Application has been stopped."
echo "Removing the old jar file..."
echo "Failed to send shutdown request."
echo "Old jar file removed successfully."
echo "Failed to remove old jar file."
echo "Replacing with the new jar file..."
cp ${NEW_APP_JAR} ${APP_JAR_PATH}
echo "New jar file copied successfully."
echo "Failed to copy new jar file."
echo "Starting the application..."
nohup java -jar ${APP_JAR_PATH} > ${APP_LOG_PATH} 2>&1 &
echo $! > ${APP_PID_PATH}
echo "Application started."
echo "Deployment complete."