Linux Bash Script to install and uninstall a JAR

#!/bin/bash
 
psLine=$(ps aux | grep  '[j]ava -jar.*demo-.*.jar.*')
# -n not empty, z empty
if [ -n "$psLine" ] ; then
      currentPid=$(echo $psLine | awk '{print $2}')
      echo Current appli running detected with pid=$currentPid
      printf "First, we stop the current application : "
      kill $currentPid
      timeout 10 tail --pid=$currentPid -f /dev/null
      if [ "$?" -eq "0" ]; then #ne eq
         echo "DONE"
      else
	 kill -9 $currentPid 
	 echo "WARN"
	 echo "Gracefuly stop not working, the process was killed"
      fi
   # Do something knowing the pid exists, i.e. the process with $PID is running
fi
 
printf "Install of the new application : "
nohup java -jar ~/demo-app/demo-0.0.1-SNAPSHOT.jar > mylog.txt  2>&1 &
sleep 2
 
i=0
while [[ $i -lt 5 ]] && [[ $statusCode != *"200"* ]]
do
       statusCode=$(curl -I "localhost:5544/greeting" 2>/dev/null | head -n 1)       
       sleep 2
       ((i++))
done
 
if [[ $statusCode == *"200"* ]]; then
  echo "DONE"
else
  echo "ERROR"
  echo The test url has returned bad responses. The last one : $statusCode	
  echo Please check the application state. To rollback use the script fooScript...
fi
Ce contenu a été publié dans Non classé. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *