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?
Asked
Active
Viewed 1,724 times
1 Answers
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
- Stop and Start a service via batch or cmd file?
- Batch file to check if a system service is running
- http://www.geekstogo.com/forum/topic/207306-start-and-stop-services-in-a-single-batch-file/
Other Options:
- If you are using any monitoring service like nagios you can monitor jenkins service from it too.

Community
- 1
- 1

Chandan Nayak
- 10,117
- 5
- 26
- 36