|
| 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 -eu -o pipefail |
| 18 | + |
| 19 | +# Check 4294967295 to detect UserNS (https://github.com/opencontainers/runc/blob/v1.0.0/libcontainer/userns/userns_linux.go#L29-L32) |
| 20 | +if grep -Eq "0[[:space:]]+0[[:space:]]+4294967295" /proc/self/uid_map; then |
| 21 | + echo >&2 "ERROR: Needs to be executed in UserNS (i.e., rootless Docker/Podman/nerdctl)" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +if [ ! -f "/sys/fs/cgroup/cgroup.controllers" ]; then |
| 26 | + echo >&2 "ERROR: Needs cgroup v2" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +for f in cpu memory pids; do |
| 31 | + if ! grep -qw "$f" "/sys/fs/cgroup/cgroup.controllers"; then |
| 32 | + echo >&2 "ERROR: Needs cgroup v2 controller ${f} to be delegated" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | +done |
| 36 | + |
| 37 | +echo >&2 "Enabling cgroup v2 nesting" |
| 38 | +# https://github.com/moby/moby/blob/v20.10.7/hack/dind#L28-L38 |
| 39 | +mkdir -p /sys/fs/cgroup/init |
| 40 | +xargs -rn1 < /sys/fs/cgroup/cgroup.procs > /sys/fs/cgroup/init/cgroup.procs || : |
| 41 | +sed -e 's/ / +/g' -e 's/^/+/' < /sys/fs/cgroup/cgroup.controllers \ |
| 42 | + > /sys/fs/cgroup/cgroup.subtree_control |
| 43 | + |
| 44 | +set -x |
| 45 | +echo >&2 "Running containerd in background" |
| 46 | +containerd & |
| 47 | + |
| 48 | +echo >&2 "Waiting for containerd" |
| 49 | +until ctr plugins list; do sleep 3; done |
| 50 | + |
| 51 | +exec "$@" |
0 commit comments