Debian Codegraph @

script/demo-store/run.sh

raw
1 #!/bin/bash
2
3 # Copyright The containerd Authors.
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8
9 # http://www.apache.org/licenses/LICENSE-2.0
10
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 set -euo pipefail
18
19 REPO=$GOPATH/src/github.com/containerd/stargz-snapshotter
20 REG_STORAGE_CONFIG_FILE="/etc/stargz-store/config.toml"
21 REG_STORAGE_ROOT=/var/lib/stargz-store/
22 REG_STORAGE_MOUNTPOINT="${REG_STORAGE_ROOT}store/"
23
24 RETRYNUM=30
25 RETRYINTERVAL=1
26 TIMEOUTSEC=180
27 function retry {
28 local SUCCESS=false
29 for i in $(seq ${RETRYNUM}) ; do
30 if eval "timeout ${TIMEOUTSEC} ${@}" ; then
31 SUCCESS=true
32 break
33 fi
34 echo "Fail(${i}). Retrying..."
35 sleep ${RETRYINTERVAL}
36 done
37 if [ "${SUCCESS}" == "true" ] ; then
38 return 0
39 else
40 return 1
41 fi
42 }
43
44 function kill_all {
45 if [ "${1}" != "" ] ; then
46 ps aux | grep "${1}" \
47 | grep -v grep \
48 | grep -v "hello.py" \
49 | grep -v $(basename ${0}) \
50 | sed -E 's/ +/ /g' | cut -f 2 -d ' ' | xargs -I{} kill -9 {} || true
51 fi
52 }
53
54 function cleanup {
55 podman system reset -f || true
56 umount "${REG_STORAGE_MOUNTPOINT}" || true
57 rm -rf "${REG_STORAGE_ROOT}"*
58 }
59
60 echo "cleaning up the environment..."
61 cleanup
62 kill_all "stargz-store"
63
64 echo "copying config from repo..."
65 cp -R "${REPO}/script/demo-store/etc/"* "/etc/"
66
67 echo "preparing commands..."
68 ( cd "${REPO}" && PREFIX=/tmp/out/ make clean && \
69 PREFIX=/tmp/out/ make -j2 && \
70 PREFIX=/tmp/out/ make install )
71
72 echo "running stargz store..."
73 mkdir -p "${REG_STORAGE_MOUNTPOINT}"
74 stargz-store --log-level=debug \
75 --config="${REG_STORAGE_CONFIG_FILE}" \
76 "${REG_STORAGE_MOUNTPOINT}" &
77 retry ls "${REG_STORAGE_ROOT}store/pool"