Update hack/dind to match the rest of our scripts
| ... | ... |
@@ -1,4 +1,5 @@ |
| 1 | 1 |
#!/bin/bash |
| 2 |
+set -e |
|
| 2 | 3 |
|
| 3 | 4 |
# DinD: a wrapper script which allows docker to be run inside a docker container. |
| 4 | 5 |
# Original version by Jerome Petazzoni <jerome@dotcloud.com> |
| ... | ... |
@@ -15,29 +16,28 @@ export container=docker |
| 15 | 15 |
# First, make sure that cgroups are mounted correctly. |
| 16 | 16 |
CGROUP=/sys/fs/cgroup |
| 17 | 17 |
|
| 18 |
-[ -d $CGROUP ] || |
|
| 19 |
- mkdir $CGROUP |
|
| 18 |
+mkdir -p "$CGROUP" |
|
| 20 | 19 |
|
| 21 |
-mountpoint -q $CGROUP || |
|
| 20 |
+if ! mountpoint -q "$CGROUP"; then |
|
| 22 | 21 |
mount -n -t tmpfs -o uid=0,gid=0,mode=0755 cgroup $CGROUP || {
|
| 23 |
- echo "Could not make a tmpfs mount. Did you use --privileged?" |
|
| 22 |
+ echo >&2 'Could not make a tmpfs mount. Did you use --privileged?' |
|
| 24 | 23 |
exit 1 |
| 25 | 24 |
} |
| 25 |
+fi |
|
| 26 | 26 |
|
| 27 |
-if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security |
|
| 28 |
-then |
|
| 29 |
- mount -t securityfs none /sys/kernel/security || {
|
|
| 30 |
- echo "Could not mount /sys/kernel/security." |
|
| 31 |
- echo "AppArmor detection and -privileged mode might break." |
|
| 32 |
- } |
|
| 27 |
+if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security; then |
|
| 28 |
+ mount -t securityfs none /sys/kernel/security || {
|
|
| 29 |
+ echo >&2 'Could not mount /sys/kernel/security.' |
|
| 30 |
+ echo >&2 'AppArmor detection and -privileged mode might break.' |
|
| 31 |
+ } |
|
| 33 | 32 |
fi |
| 34 | 33 |
|
| 35 | 34 |
# Mount the cgroup hierarchies exactly as they are in the parent system. |
| 36 |
-for SUBSYS in $(cut -d: -f2 /proc/1/cgroup) |
|
| 37 |
-do |
|
| 38 |
- [ -d $CGROUP/$SUBSYS ] || mkdir $CGROUP/$SUBSYS |
|
| 39 |
- mountpoint -q $CGROUP/$SUBSYS || |
|
| 40 |
- mount -n -t cgroup -o $SUBSYS cgroup $CGROUP/$SUBSYS |
|
| 35 |
+for SUBSYS in $(cut -d: -f2 /proc/1/cgroup); do |
|
| 36 |
+ mkdir -p "$CGROUP/$SUBSYS" |
|
| 37 |
+ if ! mountpoint -q $CGROUP/$SUBSYS; then |
|
| 38 |
+ mount -n -t cgroup -o "$SUBSYS" cgroup "$CGROUP/$SUBSYS" |
|
| 39 |
+ fi |
|
| 41 | 40 |
|
| 42 | 41 |
# The two following sections address a bug which manifests itself |
| 43 | 42 |
# by a cryptic "lxc-start: no ns_cgroup option specified" when |
| ... | ... |
@@ -52,29 +52,37 @@ do |
| 52 | 52 |
# Systemd and OpenRC (and possibly others) both create such a |
| 53 | 53 |
# cgroup. To avoid the aforementioned bug, we symlink "foo" to |
| 54 | 54 |
# "name=foo". This shouldn't have any adverse effect. |
| 55 |
- echo $SUBSYS | grep -q ^name= && {
|
|
| 56 |
- NAME=$(echo $SUBSYS | sed s/^name=//) |
|
| 57 |
- ln -s $SUBSYS $CGROUP/$NAME |
|
| 58 |
- } |
|
| 55 |
+ name="${SUBSYS#name=}"
|
|
| 56 |
+ if [ "$name" != "$SUBSYS" ]; then |
|
| 57 |
+ ln -s "$SUBSYS" "$CGROUP/$name" |
|
| 58 |
+ fi |
|
| 59 | 59 |
|
| 60 | 60 |
# Likewise, on at least one system, it has been reported that |
| 61 | 61 |
# systemd would mount the CPU and CPU accounting controllers |
| 62 | 62 |
# (respectively "cpu" and "cpuacct") with "-o cpuacct,cpu" |
| 63 | 63 |
# but on a directory called "cpu,cpuacct" (note the inversion |
| 64 | 64 |
# in the order of the groups). This tries to work around it. |
| 65 |
- [ $SUBSYS = cpuacct,cpu ] && ln -s $SUBSYS $CGROUP/cpu,cpuacct |
|
| 65 |
+ if [ "$SUBSYS" = 'cpuacct,cpu' ]; then |
|
| 66 |
+ ln -s "$SUBSYS" "$CGROUP/cpu,cpuacct" |
|
| 67 |
+ fi |
|
| 66 | 68 |
done |
| 67 | 69 |
|
| 68 | 70 |
# Note: as I write those lines, the LXC userland tools cannot setup |
| 69 | 71 |
# a "sub-container" properly if the "devices" cgroup is not in its |
| 70 | 72 |
# own hierarchy. Let's detect this and issue a warning. |
| 71 |
-grep -q :devices: /proc/1/cgroup || |
|
| 72 |
- echo "WARNING: the 'devices' cgroup should be in its own hierarchy." |
|
| 73 |
-grep -qw devices /proc/1/cgroup || |
|
| 74 |
- echo "WARNING: it looks like the 'devices' cgroup is not mounted." |
|
| 73 |
+if ! grep -q :devices: /proc/1/cgroup; then |
|
| 74 |
+ echo >&2 'WARNING: the "devices" cgroup should be in its own hierarchy.' |
|
| 75 |
+fi |
|
| 76 |
+if ! grep -qw devices /proc/1/cgroup; then |
|
| 77 |
+ echo >&2 'WARNING: it looks like the "devices" cgroup is not mounted.' |
|
| 78 |
+fi |
|
| 75 | 79 |
|
| 76 | 80 |
# Mount /tmp |
| 77 | 81 |
mount -t tmpfs none /tmp |
| 78 | 82 |
|
| 79 |
-[ "$1" ] && exec "$@" |
|
| 80 |
-echo "You probably want to run hack/make.sh, or maybe a shell?" |
|
| 83 |
+if [ $# -gt 0 ]; then |
|
| 84 |
+ exec "$@" |
|
| 85 |
+fi |
|
| 86 |
+ |
|
| 87 |
+echo >&2 'ERROR: No command specified.' |
|
| 88 |
+echo >&2 'You probably want to run hack/make.sh, or maybe a shell?' |