| 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 |
CONTAINERD_ROOT=/var/lib/containerd/ |
| 20 |
CONTAINERD_CONFIG_DIR=/etc/containerd/ |
| 21 |
REMOTE_SNAPSHOTTER_SOCKET=/run/containerd-stargz-grpc/containerd-stargz-grpc.sock |
| 22 |
REMOTE_SNAPSHOTTER_ROOT=/var/lib/containerd-stargz-grpc/ |
| 23 |
REMOTE_SNAPSHOTTER_CONFIG_DIR=/etc/containerd-stargz-grpc/ |
| 24 |
|
| 25 |
RETRYNUM=30 |
| 26 |
RETRYINTERVAL=1 |
| 27 |
TIMEOUTSEC=180 |
| 28 |
function retry { |
| 29 |
local SUCCESS=false |
| 30 |
for i in $(seq ${RETRYNUM}) ; do |
| 31 |
if eval "timeout ${TIMEOUTSEC} ${@}" ; then |
| 32 |
SUCCESS=true |
| 33 |
break |
| 34 |
fi |
| 35 |
echo "Fail(${i}). Retrying..." |
| 36 |
sleep ${RETRYINTERVAL} |
| 37 |
done |
| 38 |
if [ "${SUCCESS}" == "true" ] ; then |
| 39 |
return 0 |
| 40 |
else |
| 41 |
return 1 |
| 42 |
fi |
| 43 |
} |
| 44 |
|
| 45 |
function kill_all { |
| 46 |
if [ "${1}" != "" ] ; then |
| 47 |
ps aux | grep "${1}" \ |
| 48 |
| grep -v "benchmark" \ |
| 49 |
| grep -v grep \ |
| 50 |
| grep -v "hello.py" \ |
| 51 |
| grep -v $(basename ${0}) \ |
| 52 |
| sed -E 's/ +/ /g' | cut -f 2 -d ' ' | xargs -I{} kill -9 {} || true |
| 53 |
fi |
| 54 |
} |
| 55 |
|
| 56 |
function cleanup { |
| 57 |
rm -rf "${CONTAINERD_ROOT}"* |
| 58 |
if [ -f "${REMOTE_SNAPSHOTTER_SOCKET}" ] ; then |
| 59 |
rm "${REMOTE_SNAPSHOTTER_SOCKET}" |
| 60 |
fi |
| 61 |
if [ -d "${REMOTE_SNAPSHOTTER_ROOT}snapshotter/snapshots/" ] ; then |
| 62 |
find "${REMOTE_SNAPSHOTTER_ROOT}snapshotter/snapshots/" \ |
| 63 |
-maxdepth 1 -mindepth 1 -type d -exec umount "{}/fs" \; |
| 64 |
fi |
| 65 |
rm -rf "${REMOTE_SNAPSHOTTER_ROOT}"* |
| 66 |
} |
| 67 |
|
| 68 |
echo "cleaning up the environment..." |
| 69 |
kill_all "containerd" |
| 70 |
kill_all "containerd-stargz-grpc" |
| 71 |
cleanup |
| 72 |
|
| 73 |
if [ "${DISABLE_PREFETCH:-}" == "true" ] ; then |
| 74 |
sed -i 's/noprefetch = .*/noprefetch = true/g' "${REMOTE_SNAPSHOTTER_CONFIG_DIR}config.toml" |
| 75 |
else |
| 76 |
sed -i 's/noprefetch = .*/noprefetch = false/g' "${REMOTE_SNAPSHOTTER_CONFIG_DIR}config.toml" |
| 77 |
fi |
| 78 |
|
| 79 |
if [ "${DISABLE_ESTARGZ:-}" == "true" ] ; then |
| 80 |
echo "DO NOT RUN remote snapshotter" |
| 81 |
else |
| 82 |
echo "running remote snaphsotter..." |
| 83 |
if [ "${LOG_FILE:-}" == "" ] ; then |
| 84 |
LOG_FILE=/dev/null |
| 85 |
fi |
| 86 |
containerd-stargz-grpc --log-level=debug \ |
| 87 |
--address="${REMOTE_SNAPSHOTTER_SOCKET}" \ |
| 88 |
--config="${REMOTE_SNAPSHOTTER_CONFIG_DIR}config.toml" \ |
| 89 |
2>&1 | tee -a "${LOG_FILE}" & # Dump all log |
| 90 |
retry ls "${REMOTE_SNAPSHOTTER_SOCKET}" |
| 91 |
fi |
| 92 |
echo "running containerd..." |
| 93 |
containerd --config="${CONTAINERD_CONFIG_DIR}config.toml" & |
| 94 |
CTRCMD=ctr-remote |
| 95 |
if ! which "${CTRCMD}" ; then |
| 96 |
if ! which ctr ; then |
| 97 |
echo "ctr nor ctr-remote not found" |
| 98 |
exit 1 |
| 99 |
fi |
| 100 |
CTRCMD=ctr |
| 101 |
fi |
| 102 |
retry "${CTRCMD}" version |