This repository has been archived by the owner on Aug 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathapply.sh
executable file
·91 lines (70 loc) · 1.68 KB
/
apply.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
83
84
85
86
87
88
89
90
91
#!/bin/bash
set -e
trap cleanup EXIT
cleanup()
{
local exit=$?
if [ -e $TEMP ]; then
rm -rf $TEMP
fi
if [ -e $OLD ]; then
rm -rf $OLD
fi
return $exit
}
source ${CATTLE_HOME:-/var/lib/cattle}/common/scripts.sh
DEST=$CATTLE_HOME/pyagent
MAIN=$DEST/main.py
STAMP=$CATTLE_HOME/.pyagent-stamp
OLD=$(mktemp -d ${DEST}.XXXXXXXX)
TEMP=$(mktemp -d ${DEST}.XXXXXXXX)
cd $(dirname $0)
stage()
{
if [[ -n "${CURL_CA_BUNDLE}" && -e ./dist/websocket/cacert.pem ]]; then
if [ ! -e ./dist/websocket/cacert.orig ]; then
cp ./dist/websocket/cacert.pem ./dist/websocket/cacert.orig
fi
cat ./dist/websocket/cacert.orig ${CURL_CA_BUNDLE} > ./dist/websocket/cacert.pem
fi
cp -rf apply.sh cattle dist main.py $TEMP
find $TEMP -name "*.sh" -exec chmod +x {} \;
find $TEMP \( -name host-api -o -name cadvisor -o -name nsenter -o -name socat \) -exec chmod +x {} \;
if [ -e $DEST ]; then
mv $DEST ${OLD}
fi
mv $TEMP ${DEST}
rm -rf ${OLD}
echo $RANDOM > $STAMP
}
conf()
{
CONF=(${CATTLE_HOME}/pyagent/agent.conf
/etc/cattle/agent/agent.conf
${CATTLE_HOME}/etc/cattle/agent/agent.conf
/var/lib/rancher/etc/agent.conf)
for conf_file in "${CONF[@]}"; do
if [ -e $conf_file ]
then
source $conf_file
fi
done
}
start()
{
export PATH=${CATTLE_HOME}/bin:$PATH
chmod +x $MAIN
if [ "$CATTLE_PYPY" = "true" ] && which pypy >/dev/null; then
MAIN="pypy $MAIN"
fi
info Executing $MAIN
cleanup
$CATTLE_HOME/config.sh host-config
exec $MAIN
}
conf
if [ "$1" = "start" ]; then
start
else
stage
fi