forked from JetBrains/teamcity-docker-minimal-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-agent.sh
82 lines (67 loc) · 2.29 KB
/
run-agent.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
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
check() {
if [[ $? != 0 ]]; then
echo "Error! Stopping the script."
exit 1
fi
}
configure() {
if [[ $# -gt 0 ]]; then
echo "run agent.sh configure $@"
${AGENT_DIST}/bin/agent.sh configure "$@"; check
fi
}
reconfigure() {
declare -a opts
[[ -n "${SERVER_URL}" ]] && opts[${#opts[@]}]='--server-url' && opts[${#opts[@]}]="$SERVER_URL"
[[ -n "${AGENT_TOKEN}" ]] && opts[${#opts[@]}]='--auth-token' && opts[${#opts[@]}]="$AGENT_TOKEN"
[[ -n "${AGENT_NAME}" ]] && opts[${#opts[@]}]='--name' && opts[${#opts[@]}]="$AGENT_NAME"
[[ -n "${OWN_ADDRESS}" ]] && opts[${#opts[@]}]='--ownAddress' && opts[${#opts[@]}]="$OWN_ADDRESS"
[[ -n "${OWN_PORT}" ]] && opts[${#opts[@]}]='--ownPort' && opts[${#opts[@]}]="$OWN_PORT"
if [[ 0 -ne "${#opts[@]}" ]]; then
# Using sed to strip double quotes produced by docker-compose
for i in $(seq 0 $(expr ${#opts[@]} - 1)); do
opts[$i]="$(echo "${opts[$i]}" | sed -e 's/""/"/g')"
done
configure "${opts[@]}"
echo "File buildAgent.properties was updated"
fi
for AGENT_OPT in ${AGENT_OPTS}; do
echo ${AGENT_OPT} >> ${CONFIG_DIR}/buildAgent.properties
done
}
prepare_conf() {
echo "Will prepare agent config" ;
cp -p ${AGENT_DIST}/conf/*.* ${CONFIG_DIR}/; check
cp -p ${CONFIG_DIR}/buildAgent.dist.properties ${CONFIG_DIR}/buildAgent.properties; check
reconfigure
echo "File buildAgent.properties was created and updated" ;
}
AGENT_DIST=/opt/buildagent
CONFIG_DIR=/data/teamcity_agent/conf
LOG_DIR=/opt/buildagent/logs
chmod +x ${AGENT_DIST}/bin/*.sh; check; sync
rm -f ${LOG_DIR}/*.pid
if [ -f ${CONFIG_DIR}/buildAgent.properties ] ; then
echo "File buildAgent.properties was found in ${CONFIG_DIR}" ;
reconfigure
else
echo "Will create new buildAgent.properties using distributive" ;
if [[ -n "${SERVER_URL}" ]]; then
echo "TeamCity URL is provided: ${SERVER_URL}"
else
echo "TeamCity URL is not provided, but is required."
exit 1
fi
prepare_conf
fi
${AGENT_DIST}/bin/agent.sh start
while [ ! -f ${LOG_DIR}/teamcity-agent.log ];
do
echo -n "."
sleep 1
done
trap "${AGENT_DIST}/bin/agent.sh stop; exit 0;" SIGINT SIGTERM SIGHUP
touch /root/anchor
tail -qF ${LOG_DIR}/teamcity-agent.log /root/anchor &
wait