Restarter script for Jenkins
- I am fighting with my Jenkins instance being down every other day.
- Getting bored of sshing to the host and restart the instance, I wrote a small restarter script.
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
#!/usr/bin/python | |
""" | |
Simple restarter for jenkins - not a real Tanuki wrapper :-). | |
- Install to /usr/local/bin and make the script executable. | |
- Then create a cron entry to execute the script every 10 minutes: | |
cat << EOF > /etc/cron.d/restartjenkins | |
*/10 * * * * root /usr/local/bin/restartjenkins.py 2>&1 | logger -t restartjenkins | |
EOF | |
""" | |
import os | |
import sys | |
import urllib2 | |
SERVICE_TO_RESTART = "/etc/init.d/jenkins restart" | |
URL_TO_CHECK = os.getenv("URL_TO_CHECK", "http://127.0.0.1:8000/hudson/") | |
def restart(): | |
os.system(SERVICE_TO_RESTART) | |
if __name__ == "__main__": | |
try: | |
urllib2.urlopen(URL_TO_CHECK) | |
open("/tmp/%s.timestamp" % os.path.basename(sys.argv[0]), "w").write(URL_TO_CHECK) | |
except urllib2.URLError, e: | |
error = sys.exc_info() | |
error_message = "%s\n%s" % (error[0], error[1]) | |
sys.stderr.write(error_message) | |
restart() |
Do you have a specific reason for not using JSW?
ReplyDelete