Skip to content

Instantly share code, notes, and snippets.

@geerlingguy
Created March 5, 2018 03:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geerlingguy/2411761b7468cea7af070b33f9504c86 to your computer and use it in GitHub Desktop.
Save geerlingguy/2411761b7468cea7af070b33f9504c86 to your computer and use it in GitHub Desktop.
Make sure Jenkins is always running. This script is meant to be run on a cron job under the root user.
#!/bin/bash
#
# Makes sure Jenkins is running.
# Function to restart Jenkins, record the occurrence, and exit.
restart_jenkins() {
/usr/sbin/service jenkins restart > /dev/null
echo `date` "Restarted Jenkins" >> ~/jenkins-restarts
echo "Restarted Jenkins."
exit
}
# If Jenkins is not running, restart it.
if ps aux | grep -v grep | grep "[j]enkins" > /dev/null
then
# Do nothing. Nothing at all.
echo "Jenkins is running." > /dev/null
else
restart_jenkins
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment