-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjenkins_init_wrapper.sh
executable file
·70 lines (58 loc) · 1.62 KB
/
jenkins_init_wrapper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Read Env Vars set by Docker
source /docker.env
if ! id jenkins &>/dev/null
then
useradd -G monit,docker -s /bin/bash -d ${JENKINS_HOME} jenkins
# Set Jenkins user password, so we can SSH
[ -z "$JENKINS_PASSWD" ] && JENKINS_PASSWD=$(openssl rand -base64 6)
echo JENKINS_PASSWORD=${JENKINS_PASSWD}
echo -e "${JENKINS_PASSWD}\n${JENKINS_PASSWD}" | passwd jenkins &>/dev/null
fi
mkdir -p ${JENKINS_HOME}/.ssh
[ "${JENKINS_SSH_PUBKEY}" ] && echo "${JENKINS_SSH_PUBKEY}" >> ${JENKINS_HOME}/.ssh/authorized_keys
chown -R jenkins ${JENKINS_HOME}
OPTS="-fsroot ${JENKINS_HOME}"
if [ -n "${JENKINS_MASTER_URL}" ]
then
OPTS+=" -master ${JENKINS_MASTER_URL}"
elif [ -n "${JENKINS_AUTODISC_ADDR}" ]
then
OPTS+=" -autoDiscoveryAddress ${JENKINS_AUTODISC_ADDR}"
fi
if [ -n "${JENKINS_EXECUTORS}" ]
then
OPTS+=" -executors ${JENKINS_EXECUTORS}"
fi
if [ -n "${JENKINS_LABELS}" ]
then
OPTS+=" -labels ${JENKINS_LABELS}"
fi
if [ -n "${JENKINS_USERNAME}" ] && [ -n "${JENKINS_PASSWORD}" ]
then
OPTS+=" -username ${JENKINS_USERNAME} -password ${JENKINS_PASSWORD}"
fi
cd ${JENKINS_HOME}
echo "### Jenkins Swarm client options ###"
echo "### ${OPTS} ###"
case $1 in
start)
su - jenkins -c "java ${JENKINS_JAVA_OPTS} -jar swarm-client.jar ${OPTS} &>$JENKINS_HOME/jenkins_swarm_client.log & echo \$! > /tmp/jenkins.pid"
;;
stop)
pkill -F /tmp/jenkins.pid
;;
status)
if pgrep -f swarm-client.jar &>/dev/null
then
echo "Jenkins Swam Client running..."
exit 0
else
echo "Jenkins Swam Client not running..."
exit 1
fi
;;
*)
echo "Usage $0 start|stop|status"
;;
esac