Skip to content

Instantly share code, notes, and snippets.

@christ66 christ66/README forked from ganthore/README
Last active Apr 4, 2019

Embed
What would you like to do?
See README below.
INSTALLATION
Copy jenkins-slave.init to /etc/init.d/jenkins-slave and copy jenkins-slave to /etc/sysconfig/jenkins-slave.
cp jenkins-slave.init /etc/init.d/jenkins-slave
cp jenkins-slave /etc/sysconfig/jenkins-slave
chkconfig jenkins-slave on
service jenkins-slave start
Change the values of /etc/sysconfig/jenkins-slave to match your environment needs.
It's critical that JENKINS_URL and JENKINS_NODENAME are set.
The node name variable must match a node that you've already defined in your Jenkins nodes.
JENKINS_WORKDIR="/opt/jenkins-slave"
JENKINS_USER="jenkins-slave"
JENKINS_URL="http://127.0.0.1:8080"
JENKINS_NODENAME="slave_name"
JENKINS_SECRET="SECRET"
#!/bin/bash
# chkconfig: - 85 15
# description: Init script for jenkins-slave
# Source function library.
. /etc/rc.d/init.d/functions
[ -f /etc/sysconfig/jenkins-slave ] && . /etc/sysconfig/jenkins-slave
[ -n "${JENKINS_URL}" ] || exit 0
[ -n "${JENKINS_WORKDIR}" ] || exit 0
[ -n "${JENKINS_USER}" ] || exit 0
[ -n "${JENKINS_NODENAME}" ] || exit 0
[ -n "${JENKINS_SECRET}" ] || exit 0
[ -x /usr/bin/java ] || exit 0
create_user()
{
awk -F":" '{ print $1 }' /etc/passwd | grep -x ${JENKINS_USER} > /dev/null
if [ $? -eq 1 ]; then
useradd ${JENKINS_USER} -d ${JENKINS_WORKDIR} -s /bin/false
fi
}
create_dir()
{
if [ ! -d ${JENKINS_WORKDIR} ];
then
mkdir -p ${JENKINS_WORKDIR}
fi
}
create_logdir()
{
if [ ! -d /var/log/jenkins-slave ];
then
mkdir -p /var/log/jenkins-slave
chown -R ${JENKINS_USER}:${JENKINS_USER} /var/log/jenkins-slave
fi
}
download_jar()
{
curl -s -o ${JENKINS_WORKDIR}/slave.jar ${JENKINS_URL}/jnlpJars/slave.jar || exit 0
chown -R ${JENKINS_USER}:${JENKINS_USER} ${JENKINS_WORKDIR}
}
start()
{
create_user
create_dir
create_logdir
cd ${JENKINS_WORKDIR}
[ -f slave.jar ] || download_jar
echo -e $"Starting Jenkins BuildSlave..."
su - ${JENKINS_USER} sh -s /bin/bash -c "\
/usr/bin/java -jar ${JENKINS_WORKDIR}/slave.jar \
-jnlpUrl ${JENKINS_URL}/computer/${JENKINS_NODENAME}/slave-agent.jnlp \
-secret ${JENKINS_SECRET} \
>/var/log/jenkins-slave/jenkins-slave.log 2>&1 &"
}
stop()
{
echo -e $"Shutting down Jenkins BuildSlave..."
pkill -f 'java.*slave.jar'
}
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.