jason-w
4/21/2017 - 6:15 PM

Bash - Shutdown AEM service

Bash - Shutdown AEM service

# SHUTDOWN AEM SERVICE
shutdown_tries=0 # try normal shutdown 2x then kill the procsses            
while : ; do
  # tried twice to shut down normally
  if [ $shutdown_tries -eq 2 ]; then
    echo "$(ts): Attempting to kill AEM process"
    
    # grab the PID of the java running process
    # jlw: this will break if there is more than one java process running.
    # PID=$(pgrep java)
    PID=$(cat $aemfolder/conf/cq.pid 2>/dev/null)
       
    rm -f $aemfolder/conf/cq.pid

    if ps -p $PID > /dev/null 2>&1; then
      kill $PID
      sleep 60 # sleep 60 seconds
      echo "$(ts): process ${PID} was killed"
    else
      echo "$(ts): process ${PID} not running"
    fi

  else
    check_process "java"

    if [ $? -eq 1 ]; then 
      echo "$(ts): Attempting shut down of aem service"
      $aemfolder/bin/stop
      shutdown_tries=$[$shutdown_tries+1]
      echo "$(ts): Waiting 120 seconds before checking again."
      sleep 120
    else
      echo "$(ts): AEM Service shutdown successful. Starting compression proceedures."
      break
    fi
  fi
done