$ vi jenkins_health_chk.sh

#!/bin/bash

url='http://jenkins.domain.com/'
attempts=3
timeout=10
online=false
nowdate=$(date +"%Y-%m-%d %H:%M:%S")

echo "Checking status of $url."

for (( i=1; i<=$attempts; i++ ))
do
  code=`curl -sL --connect-timeout 20 --max-time 30 -w "%{http_code}\\n" "$url" -o /dev/null`

  if [ "$code" = "403" ]; then
    online=true
    break
  else
    sleep $timeout
  fi
done

if $online; then
  echo "Monitor finished, website is online."
else
  echo "Monitor failed, website seems to be down."
  sudo systemctl restart jenkins
  echo "${nowdate} jenkins restart!" >> /home/ubuntu/script/cron_run.log
fi

 

#권한부여
chmod 755 jenkins_health_chk.sh

#크론등록
crontab -e

*/5 * * * * /home/ubuntu/script/jenkins_health_chk.sh

 

 

'Infra Structure > Jenkins' 카테고리의 다른 글

[Jenkins] 백업 / 복구  (0) 2022.06.03
[Jenkins] Pipeline svn check out  (0) 2022.06.02
[Jenkins] Health check  (0) 2022.02.26
[Jenkins] 원격 쉘 실행  (0) 2022.02.23
[Jenkins] 배포 쉘(shell) 및 프로젝트 자동 start  (0) 2022.02.23

+ Recent posts