Created
March 5, 2018 03:10
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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