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"
15 if [ -f ${SLAVE_CONF} ]; then
18 echo "Fatal : Configuration file dosenot exist, details please refer to README."
22 if [ -z "${SLAVENAME}" ] || [ -z "${TOKEN}" ]
24 echo "Fatal : Lack of slavename and token"
28 JENKINS_HOME="/home/jenkins"
29 PID_FILE="${JENKINS_HOME}/slave.pid"
30 SLAVE_JAR="${JENKINS_HOME}/slave.jar"
31 SLAVE_JNLP="-jnlpUrl https://build.opnfv.org/ci/computer/${SLAVENAME}/slave-agent.jnlp"
33 SLAVE_LOG="${JENKINS_HOME}/slave.log"
34 JAVA_BIN="/usr/bin/java"
39 Usage: jenkins-slave {start|stop|restart}
45 echo "Starting jenkins slave(${SLAVENAME})"
46 if ! start-stop-daemon --start -m -b -c ${USER} -p ${PID_FILE} \
47 --startas /bin/bash -- -c \
48 "exec ${JAVA_BIN} -jar ${SLAVE_JAR} ${SLAVE_JNLP} -secret ${TOKEN} >>${SLAVE_LOG} 2>&1"
50 echo "Start jenkins slave failed!"
58 echo "Stopping jenkins slave(${SLAVENAME})"
59 if ! start-stop-daemon --stop -p ${PID_FILE}
61 echo "Stop jenkins slave failed!"
71 pid=`ps -ef | grep "${SLAVE_JAR}" | grep -v 'grep' | awk '{print $2}'`
75 echo "jenkins slave is not running!"
77 echo "jenkins slave is running, pid is $pid"
85 echo "None valid argument!"
106 echo "$OPTION is not a valid argument!"