0

I would like to know if there is a way to periodically check the status of the jenkins service and get an email when the service goes down?

DarthOpto
  • 1,449
  • 5
  • 27
  • 52

1 Answers1

3

On linux:
Can use ps -ef | grep -v grep | grep jenkins | wc -l to find if your jenkins is running or not , if not try to invoke email script or restart and put it in crontab.

#!/bin/bash
if (($(ps - ef | grep - v grep | grep $service | wc - l) > 0))
then
    echo "$service is running!!!"
else
    echo "Do your stuff!!"
fi

Source / example : Link

On localhost, you can check for the HTTP code URL assuming jenkins is running on 8080

#!/bin/bash
response=$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:8080)
if [ $response  == 200 ]
then
    echo "Site is up"
else
    echo "Site is down"
    echo "Do your stuff!!"
fi

On windows:
you can do simillar with form a batch script using:
sc query service | findstr /i running | if "%errorlevel%"=="0" (sc stop service) else (sc start service)

More links to read on this

Other Options:

  • If you are using any monitoring service like nagios you can monitor jenkins service from it too.

Sending mail from Python using SMTP

Community
  • 1
  • 1
Chandan Nayak
  • 7,619
  • 5
  • 22
  • 33