Jenkins Recycle/Restart Script for Ubuntu

7 views
Skip to first unread message

Julian Biddle

unread,
Oct 4, 2016, 7:57:43 PM10/4/16
to Jenkins Users
I have troubles where jenkins gets slower and slower, then crashes.  I will be investigating the problem, but in the interim I created a script that others might be interested in.

It is designed to perform a "safe restart" (which waits for builds to finish).

I run this every 2 hours using cron:

0 */2 * * * $HOME/bin/restartjenkins.sh >> $HOME/logs/restartjenkins.log


Here's the script:

restartjenkins.sh 

#!/bin/bash


JENKINSPROCESS
=`ps -U jenkins | grep systemd`
if [[ -z $JENKINSPROCESS ]]
then
        echo
"ERROR: Jenkins Process not detected!!!...Trying to start"
       
# Attempt a normal start
        sudo
/etc/init.d/jenkins start
       
exit
fi
echo
"Attempting Safe Jenkins Restart"
USER
=xxxxxxxxxx
APITOKEN
=xxxxxxxxxxxx
SERVER
="http://localhost:8080"
CRUMB
=$(curl --user $USER:$APITOKEN \
    $SERVER
/crumbIssuer/api/xml?xpath=concat\(//crumbRequestField,%22:%22,//crumb\))


curl
-X POST -u $USER:$APITOKEN -H "$CRUMB" "$SERVER/safeRestart"


Reply all
Reply to author
Forward
0 new messages