Created
July 28, 2016 20:21
-
-
Save wesleyit/d2bfbc9cf104c6764b95364260f5331b to your computer and use it in GitHub Desktop.
This script will keep a jenkins slave always running.
This file contains hidden or 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 | |
## Set here the Jenkins URL to enable this slave | |
# and its secret | |
export JENKINS_URL='' | |
export SECRET='' | |
export JENKINS_IP='' | |
function test_master_conn() { | |
ping -c 4 "$JENKINS_IP" &> /dev/null | |
return $? | |
} | |
function test_google_conn() { | |
ping -c 4 www.google.com.br &> /dev/null | |
return $? | |
} | |
function start_slave() { | |
echo "Process [ FAIL ]" | |
echo "Trying to start the slave process..." | |
java -jar slave.jar -jnlpUrl "$JENKINS_URL" -secret "$SECRET" \ | |
&> /dev/null & | |
sleep 5 | |
disown | |
if is_running; then | |
success "Slave process started successfully!" | |
else | |
fail "Failure starting the slave process." | |
fi | |
return $? | |
} | |
function is_running() { | |
ps -ef | | |
grep -v grep | | |
grep -q 'java -jar slave.jar' | |
return $? | |
} | |
function fail() { | |
echo "$@" | |
echo "Trying again in 60 seconds..." | |
sleep 60 | |
return 1 | |
} | |
function success() { | |
echo "$@" | |
return 0 | |
} | |
while true; do | |
test_google_conn && success "Internet [ OK ]" || fail "Internet [ FAIL ]" | |
test_master_conn && success "Master [ OK ]" || fail "Master [ FAIL ]" | |
is_running && success "Process [ OK ]" || start_slave | |
sleep 60 | |
echo '------------------------------------------------------------' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment