2 ##############################################################################
3 # Copyright (c) 2015 Huawei Technologies Co.,Ltd.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0#
9 ##############################################################################
14 SLAVE_CONF="/etc/default/jenkins-slave"
16 if [ -f ${SLAVE_CONF} ]
20 echo "Error : Configuration file ($SLAVE_CONF) does not exist, details please refer to README."
24 if [ -z "${SLAVENAME}" ] || [ -z "${TOKEN}" ]
26 echo "Error : Please define SLAVENAME and TOKEN values in the Configuration file ($SLAVE_CONF), details please refer to README."
30 SLAVE_JNLP="-jnlpUrl https://build.opnfv.org/ci/computer/${SLAVENAME}/slave-agent.jnlp"
31 JENKINS_HOME="/home/jenkins"
32 SLAVE_JAR="${JENKINS_HOME}/slave.jar"
33 JENKINS_SLAVE_ROOTDIR="${JENKINS_HOME}/jenkins-slave"
34 PID_FILE="${JENKINS_SLAVE_ROOTDIR}/slave.pid"
35 SLAVE_LOG="${JENKINS_SLAVE_ROOTDIR}/slave.log"
38 JAVA_BIN="/usr/bin/java"
40 if [ ! -f ${SLAVE_JAR} ]
42 echo "Error : ${SLAVE_JAR} dosenot exist, details please refer to README."
46 [ -e ${JENKINS_SLAVE_ROOTDIR} ] || { mkdir ${JENKINS_SLAVE_ROOTDIR}; chown ${USER}:${GROUP} ${JENKINS_SLAVE_ROOTDIR};};
47 if [ ! -d ${JENKINS_SLAVE_ROOTDIR} ]
49 echo "Error : ${JENKINS_SLAVE_ROOTDIR} can not be created! Maybe there is a file with the same name of 'jenkins-slave'."
56 Usage: jenkins-slave {start|stop|restart}
62 echo "Starting jenkins slave(${SLAVENAME})"
63 if ! start-stop-daemon --start -m -b -c ${USER} -p ${PID_FILE} \
64 --startas /bin/bash -- -c \
65 "exec ${JAVA_BIN} -jar ${SLAVE_JAR} ${SLAVE_JNLP} -secret ${TOKEN} >>${SLAVE_LOG} 2>&1"
67 echo "Start jenkins slave failed!"
75 echo "Stopping jenkins slave(${SLAVENAME})"
76 if ! start-stop-daemon --stop -p ${PID_FILE}
78 echo "Stop jenkins slave failed!"
88 pid=`ps -ef | grep "${SLAVE_JAR}" | grep -v 'grep' | awk '{print $2}'`
92 echo "jenkins slave is not running!"
94 echo "jenkins slave is running, pid is $pid"
102 echo "Please input your argument!"
123 echo "Error: $OPTION is not a valid argument"