$ 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