forked from voxpupuli/puppet-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins-slave.RedHat.erb
132 lines (114 loc) · 2.62 KB
/
jenkins-slave.RedHat.erb
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
#
# /etc/init.d/jenkins-slave
# init script for Jenkins Slave Swarm Client.
#
# chkconfig: 2345 90 60
# description: Jenkins Slave Swarm Client
#
RETVAL=0
NAME=jenkins-slave
JENKINS_CONFIG=/etc/sysconfig/$NAME
LOCK_FILE=/var/lock/subsys/$NAME
PIDFILE=/var/run/$NAME/$NAME.pid
# Source function library.
. /etc/init.d/functions
# Read config
[ -f "$JENKINS_CONFIG" ] && . "$JENKINS_CONFIG"
if [ -x /sbin/runuser ] ; then
RUNUSER=runuser
else
RUNUSER=su
fi
slave_start() {
echo Starting Jenkins Slave...
# the default location is /var/run/jenkins/jenkins.pid but the parent directory needs to be created
mkdir `dirname $PIDFILE` > /dev/null 2>&1 || true
chown $JENKINS_SLAVE_USER `dirname $PIDFILE`
# create log directory
mkdir -p `dirname $JENKINS_SLAVE_LOG` > /dev/null 2>&1 || true
chown $JENKINS_SLAVE_USER -R `dirname $JENKINS_SLAVE_LOG`
# export is required for sysconfig values to be inherited by the su/runuser
# env
export_sysconfig
# --user in daemon doesn't prepare environment variables like HOME, USER, LOGNAME or USERNAME,
# so we let su do so for us now
$RUNUSER $JENKINS_SLAVE_USER -c "<%= scope['jenkins::slave::slave_home'] %>/jenkins-slave-run >> $JENKINS_SLAVE_LOG 2>&1 &"
# the shell may take a moment to exec the jvm causing pgrep to come up empty
sleep 1
pgrep -f -u $JENKINS_SLAVE_USER $JENKINS_SLAVE_JAR > $PIDFILE
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
}
slave_stop() {
echo Stopping Jenkins Slave...
pid=`cat $PIDFILE`
killproc -p $PIDFILE
# Wait until the monitor exits
while (checkpid $pid)
do
usleep 100000
done
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
}
slave_restart() {
echo Restarting Jenkins Slave...
slave_stop
slave_start
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
}
slave_status() {
echo Jenkins Slave status:
status -p $PIDFILE
RETVAL=$?
}
export_sysconfig() {
local sysconfig=(
JAVA
JAVA_ARGS
JENKINS_SLAVE_USER
JENKINS_SLAVE_JAR
JENKINS_SLAVE_LOG
JENKINS_SLAVE_MODE
MAXOPENFILES
MASTER_URL
AUTO_DISCOVERY_ADDRESS
LABELS
EXECUTORS
CLIENT_NAME
FSROOT
DESCRIPTION
TUNNEL
JENKINS_USERNAME
JENKINS_PASSWORD
OTHER_ARGS
DISABLE_CLIENTS_UNIQUE_ID
DISABLE_SSL_VERIFICATION
DELETE_EXISTING_CLIENTS
TOOL_LOCATIONS
)
for v in ${sysconfig[*]}; do
[[ -n "${v+x}" ]] && export $v
done
}
case "$1" in
start)
slave_start
;;
stop)
slave_stop
;;
restart)
slave_restart
;;
status)
slave_status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL