|
| 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 | +for arg; do |
| 26 | + case x"$arg" in |
| 27 | + x-nosnapshotter) |
| 28 | + NOSNAPSHOTTER="-nosnapshotter" |
| 29 | + ;; |
| 30 | + x-nocleanup) |
| 31 | + NOCLEANUP="-nocleanup" |
| 32 | + ;; |
| 33 | + x*) |
| 34 | + SCRAPE_OUTPUT_FILENAME="$arg" |
| 35 | + ;; |
| 36 | + esac |
| 37 | +done |
| 38 | + |
| 39 | +RETRYNUM=30 |
| 40 | +RETRYINTERVAL=1 |
| 41 | +TIMEOUTSEC=180 |
| 42 | +function retry { |
| 43 | + local SUCCESS=false |
| 44 | + for i in $(seq ${RETRYNUM}) ; do |
| 45 | + if eval "timeout ${TIMEOUTSEC} ${@}" ; then |
| 46 | + SUCCESS=true |
| 47 | + break |
| 48 | + fi |
| 49 | + echo "Fail(${i}). Retrying..." |
| 50 | + sleep ${RETRYINTERVAL} |
| 51 | + done |
| 52 | + if [ "${SUCCESS}" == "true" ] ; then |
| 53 | + return 0 |
| 54 | + else |
| 55 | + return 1 |
| 56 | + fi |
| 57 | +} |
| 58 | + |
| 59 | +function kill_all { |
| 60 | + if [ "${1}" != "" ] ; then |
| 61 | + ps aux | grep "${1}" | grep -v grep | grep -v $(basename ${0}) | sed -E 's/ +/ /g' | cut -f 2 -d ' ' | xargs -I{} kill -9 {} || true |
| 62 | + fi |
| 63 | +} |
| 64 | + |
| 65 | +function cleanup { |
| 66 | + rm -rf "${CONTAINERD_ROOT}"* |
| 67 | + if [ -f "${REMOTE_SNAPSHOTTER_SOCKET}" ] ; then |
| 68 | + rm "${REMOTE_SNAPSHOTTER_SOCKET}" |
| 69 | + fi |
| 70 | + if [ -d "${REMOTE_SNAPSHOTTER_ROOT}snapshotter/snapshots/" ] ; then |
| 71 | + find "${REMOTE_SNAPSHOTTER_ROOT}snapshotter/snapshots/" \ |
| 72 | + -maxdepth 1 -mindepth 1 -type d -exec umount "{}/fs" \; |
| 73 | + fi |
| 74 | + rm -rf "${REMOTE_SNAPSHOTTER_ROOT}"* |
| 75 | +} |
| 76 | + |
| 77 | +echo "cleaning up the environment..." |
| 78 | +kill_all "containerd" |
| 79 | +kill_all "containerd-stargz-grpc" |
| 80 | +kill_all "scrape" |
| 81 | +if [ "$NOCLEANUP" == "-nocleanup" ]; then |
| 82 | + echo "DO NOT CLEANUP containerd & stargz-snapshotter layers" |
| 83 | +else |
| 84 | + cleanup |
| 85 | +fi |
| 86 | +if [ "${NOSNAPSHOTTER}" == "-nosnapshotter" ] ; then |
| 87 | + echo "DO NOT RUN remote snapshotter" |
| 88 | +else |
| 89 | + echo "running remote snaphsotter..." |
| 90 | + containerd-stargz-grpc --log-level=debug \ |
| 91 | + --address="${REMOTE_SNAPSHOTTER_SOCKET}" \ |
| 92 | + --config="${REMOTE_SNAPSHOTTER_CONFIG_DIR}config.stargz.toml" \ |
| 93 | + &>/var/log/containerd-stargz-grpc.log & |
| 94 | + retry ls "${REMOTE_SNAPSHOTTER_SOCKET}" |
| 95 | + mkdir -p "$(dirname "${SCRAPE_OUTPUT_FILENAME}")" |
| 96 | + scrape -output "${SCRAPE_OUTPUT_FILENAME}" -netinf eth0 -interval 1s \ |
| 97 | + -pid "$(ps aux | grep -v grep | grep containerd-stargz-grpc | awk '{print $2}')" & |
| 98 | +fi |
| 99 | +echo "running containerd..." |
| 100 | +containerd --log-level debug \ |
| 101 | + --config="${CONTAINERD_CONFIG_DIR}config.containerd.toml" &>/var/log/containerd.log & |
| 102 | +retry ctr version |
0 commit comments