-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·63 lines (51 loc) · 1.5 KB
/
entrypoint.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
#!/bin/bash
chown -R puppet:puppet /etc/puppetlabs/puppet/ssl
chown -R puppet:puppet /opt/puppetlabs/server/data/puppetserver/
function loop_update_from_git {
# BEGIN Setup r10k
mkdir -p ${CACHE_DIR}
mkdir -p ${R10K_CONFIG_DIR}
/init.rb
# END Setup r10k
mkdir -p ${GIT_TEMP_DIR}
pushd ${GIT_TEMP_DIR}
CERT=$(puppet config print hostcert)
KEY=$(puppet config print hostprivkey)
CACERT=$(puppet config print localcacert)
while true; do
if [ ! -d '.git' ]; then
git init
git remote add origin ${GIT_REMOTE}
fi
last_commit=$(git ls-remote origin | cut -f1)
changed=0
git show $last_commit >/dev/null 2>/dev/null || changed=1
if [[ $changed == 1 ]]; then
git fetch --all
r10k deploy environment
pushd ${ENVIRONMENTS_BASE_DIR}
for dir in $(find . -maxdepth 1 -type d \( ! -name . \)); do
echo "Find ${dir} environment"
pushd ${dir}
librarian-puppet install
popd
done
popd
curl --resolve "$(hostname -f):8140:127.0.0.1" \
--cert ${CERT} \
--key ${KEY} \
--cacert ${CACERT} \
-X DELETE \
"https://$(hostname -f):8140/puppet-admin-api/v1/environment-cache"
fi
sleep ${GIT_TIMEOUT}
done
popd
}
if [ -n "${GIT_REMOTE}" ]; then
loop_update_from_git &
fi
if [ -n "${PUPPETDB_SERVER_URLS}" ]; then
sed -i "s@^server_urls.*@server_urls = ${PUPPETDB_SERVER_URLS}@" /etc/puppetlabs/puppet/puppetdb.conf
fi
exec /opt/puppetlabs/bin/puppetserver "$@"