-
-
Save jacksoncage/5974695 to your computer and use it in GitHub Desktop.
#!/bin/sh | |
# | |
# jenkins-slave: Launch a Jenkins BuildSlave instance on this node | |
# | |
# chkconfig: - 99 01 | |
# description: Enable this node to fulfill build jobs | |
# | |
JENKINS_WORKDIR="/var/jenkins" | |
JENKINS_USER="jenkins" | |
JENKINS_URL="http://www.domain.com/" | |
JENKINS_NODE_LINUX=`hostname -s | cut -d'0' -f1` | |
JENKINS_NODE_NR=`hostname -s | cut -d'0' -f2` | |
JENKINS_NODENAME="${JENKINS_NODE_LINUX}_slave_node_${JENKINS_NODE_NR}" | |
[ -x /usr/bin/java ] || exit 0 | |
download_jar() | |
{ | |
cd $JENKINS_WORKDIR | |
curl -s -o slave.jar $JENKINS_URL/jnlpJars/slave.jar || exit 0 | |
} | |
start() | |
{ | |
cd $JENKINS_WORKDIR | |
[ -f slave.jar ] || download_jar | |
echo -n "Starting Jenkins BuildSlave ($JENKINS_NODENAME): " | |
sh -c "\ | |
java -jar $JENKINS_WORKDIR/slave.jar \ | |
-jnlpUrl $JENKINS_URL/computer/$JENKINS_NODENAME/slave-agent.jnlp \ | |
>$JENKINS_WORKDIR/slave.log 2>&1 &" | |
echo Done. | |
} | |
stop() | |
{ | |
echo -n "Shutting down Jenkins BuildSlave ($JENKINS_NODENAME): " | |
killall -9 java | |
killall -9 java | |
echo "deleting java client file " | |
cd $JENKINS_WORKDIR | |
rm -f slave.jar | |
echo Done. | |
} | |
# See how we were called. | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart|reload) | |
stop | |
start | |
;; | |
status) | |
status java | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart|reload}" | |
exit 1 | |
esac | |
exit 0 |
#!/bin/bash | |
# | |
# Checking Jenkins offline and restart if offline | |
# | |
JENKINS_URL="http://www.domain.com/" | |
JENKINS_NODE_LINUX=`hostname -s | cut -d'0' -f1` | |
JENKINS_NODE_NR=`hostname -s | cut -d'0' -f2` | |
JENKINS_NODENAME="${JENKINS_NODE_LINUX}_slave_node_${JENKINS_NODE_NR}" | |
CHECKED=`curl --silent $JENKINS_URL/computer/$JENKINS_NODENAME/api/json | grep -Po '"offline":true' | cut -d':' -f2` | |
if [[ "$CHECKED" == "true" ]]; then | |
service jenkins-slave restart | |
echo "INFO: $JENKINS_NODENAME was offline and are now restarted" | |
exit 0 | |
fi | |
echo "INFO: $JENKINS_NODENAME is online, no need to restart." | |
exit 0 |
Hi folks,
Can I get script customized for my issue; disconnecting a windows slave connected through JNLP & reconnecting it again.
Thanks & Regards,
Sridevi
Hi everyone,
This script will not help for windows slave connected through JNLP I think because if the slave is offline, how can the job be run on the slave. If anyone has any suggestion for this please help me. I want the script to be run on windows slave (disconnecting & reconnecting a windows slave connected through JNLP using Jenkins job).
Thanks & Regards,
can i get this script customized for disconnecting a slave permanently??
Regards,
Priyanka
If you experience issues with constantly connecting & disconnecting node, this is due to java version. Check which java your jenkins use - the node has to use the same version of java for running slave.jar.
Hi,
How can get the jenkins api as mentioned in curl url.
I matched the java version, problem of slave.jar disconnection still exists. happens a log in packer build
You should remove ending slash from example domain here:
JENKINS_URL="http://www.domain.com/"
because later it gets appended with another slash:
curl -s -o slave.jar $JENKINS_URL/jnlpJars/slave.jar