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
·110 lines (82 loc) · 2.27 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/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
}
run_fio() {
info Running fio
pushd /var/lib/docker/tmp
fio --name=randwrite --ioengine=libaio --iodepth=64 --rw=randwrite --bs=4k --direct=1 --end_fsync=1 \
--size=512M --numjobs=8 --runtime=30 --group_reporting --output-format=json --output=/var/lib/rancher/state/write.json
fio --name=randread --ioengine=libaio --iodepth=64 --rw=randread --bs=4k --direct=1 --end_fsync=1 --size=512M \
--numjobs=8 --runtime=30 --group_reporting --output-format=json --output=/var/lib/rancher/state/read.json
popd
}
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
if [ "$CATTLE_RUN_FIO" == "true" ]; then
run_fio
fi
exec $MAIN
}
conf
if [ "$1" = "start" ]; then
start
else
stage
fi