Browse code

update hack/dind for 1.8 mounting of cgroups

Signed-off-by: Jessica Frazelle <acidburn@docker.com>

Jessica Frazelle authored on 2015/08/22 03:13:33
Showing 1 changed files
... ...
@@ -13,16 +13,79 @@ set -e
13 13
 # apparmor sucks and Docker needs to know that it's in a container (c) @tianon
14 14
 export container=docker
15 15
 
16
-# First, make sure that cgroups are mounted correctly.
17
-CGROUP=/cgroup
16
+# as of docker 1.8, cgroups will be mounted in the container
17
+if ! mountpoint -q /sys/fs/cgroup; then
18 18
 
19
-mkdir -p "$CGROUP"
19
+	# First, make sure that cgroups are mounted correctly.
20
+	CGROUP=/cgroup
20 21
 
21
-if ! mountpoint -q "$CGROUP"; then
22
-	mount -n -t tmpfs -o uid=0,gid=0,mode=0755 cgroup $CGROUP || {
23
-		echo >&2 'Could not make a tmpfs mount. Did you use --privileged?'
24
-		exit 1
25
-	}
22
+	mkdir -p "$CGROUP"
23
+
24
+	if ! mountpoint -q "$CGROUP"; then
25
+		mount -n -t tmpfs -o uid=0,gid=0,mode=0755 cgroup $CGROUP || {
26
+			echo >&2 'Could not make a tmpfs mount. Did you use --privileged?'
27
+			exit 1
28
+		}
29
+	fi
30
+
31
+	# Mount the cgroup hierarchies exactly as they are in the parent system.
32
+	for HIER in $(cut -d: -f2 /proc/1/cgroup); do
33
+
34
+		# The following sections address a bug which manifests itself
35
+		# by a cryptic "lxc-start: no ns_cgroup option specified" when
36
+		# trying to start containers within a container.
37
+		# The bug seems to appear when the cgroup hierarchies are not
38
+		# mounted on the exact same directories in the host, and in the
39
+		# container.
40
+
41
+		SUBSYSTEMS="${HIER%name=*}"
42
+
43
+		# If cgroup hierarchy is named(mounted with "-o name=foo") we
44
+		# need to mount it in $CGROUP/foo to create exect same
45
+		# directoryes as on host. Else we need to mount it as is e.g.
46
+		# "subsys1,subsys2" if it has two subsystems
47
+
48
+		# Named, control-less cgroups are mounted with "-o name=foo"
49
+		# (and appear as such under /proc/<pid>/cgroup) but are usually
50
+		# mounted on a directory named "foo" (without the "name=" prefix).
51
+		# Systemd and OpenRC (and possibly others) both create such a
52
+		# cgroup. So just mount them on directory $CGROUP/foo.
53
+
54
+		OHIER=$HIER
55
+		HIER="${HIER#*name=}"
56
+
57
+		mkdir -p "$CGROUP/$HIER"
58
+
59
+		if ! mountpoint -q "$CGROUP/$HIER"; then
60
+			mount -n -t cgroup -o "$OHIER" cgroup "$CGROUP/$HIER"
61
+		fi
62
+
63
+		# Likewise, on at least one system, it has been reported that
64
+		# systemd would mount the CPU and CPU accounting controllers
65
+		# (respectively "cpu" and "cpuacct") with "-o cpuacct,cpu"
66
+		# but on a directory called "cpu,cpuacct" (note the inversion
67
+		# in the order of the groups). This tries to work around it.
68
+
69
+		if [ "$HIER" = 'cpuacct,cpu' ]; then
70
+			ln -s "$HIER" "$CGROUP/cpu,cpuacct"
71
+		fi
72
+
73
+		# If hierarchy has multiple subsystems, in /proc/<pid>/cgroup
74
+		# we will see ":subsys1,subsys2,subsys3,name=foo:" substring,
75
+		# we need to mount it to "$CGROUP/foo" and if there were no
76
+		# name to "$CGROUP/subsys1,subsys2,subsys3", so we must create
77
+		# symlinks for docker daemon to find these subsystems:
78
+		# ln -s $CGROUP/foo $CGROUP/subsys1
79
+		# ln -s $CGROUP/subsys1,subsys2,subsys3 $CGROUP/subsys1
80
+
81
+		if [ "$SUBSYSTEMS" != "${SUBSYSTEMS//,/ }" ]; then
82
+			SUBSYSTEMS="${SUBSYSTEMS//,/ }"
83
+			for SUBSYS in $SUBSYSTEMS
84
+			do
85
+				ln -s "$CGROUP/$HIER" "$CGROUP/$SUBSYS"
86
+			done
87
+		fi
88
+	done
26 89
 fi
27 90
 
28 91
 if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security; then
... ...
@@ -32,65 +95,6 @@ if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security; then
32 32
 	}
33 33
 fi
34 34
 
35
-# Mount the cgroup hierarchies exactly as they are in the parent system.
36
-for HIER in $(cut -d: -f2 /proc/1/cgroup); do
37
-
38
-	# The following sections address a bug which manifests itself
39
-	# by a cryptic "lxc-start: no ns_cgroup option specified" when
40
-	# trying to start containers within a container.
41
-	# The bug seems to appear when the cgroup hierarchies are not
42
-	# mounted on the exact same directories in the host, and in the
43
-	# container.
44
-
45
-	SUBSYSTEMS="${HIER%name=*}"
46
-
47
-	# If cgroup hierarchy is named(mounted with "-o name=foo") we
48
-	# need to mount it in $CGROUP/foo to create exect same
49
-	# directoryes as on host. Else we need to mount it as is e.g.
50
-	# "subsys1,subsys2" if it has two subsystems
51
-
52
-	# Named, control-less cgroups are mounted with "-o name=foo"
53
-	# (and appear as such under /proc/<pid>/cgroup) but are usually
54
-	# mounted on a directory named "foo" (without the "name=" prefix).
55
-	# Systemd and OpenRC (and possibly others) both create such a
56
-	# cgroup. So just mount them on directory $CGROUP/foo.
57
-
58
-	OHIER=$HIER
59
-	HIER="${HIER#*name=}"
60
-
61
-	mkdir -p "$CGROUP/$HIER"
62
-
63
-	if ! mountpoint -q "$CGROUP/$HIER"; then
64
-		mount -n -t cgroup -o "$OHIER" cgroup "$CGROUP/$HIER"
65
-	fi
66
-
67
-	# Likewise, on at least one system, it has been reported that
68
-	# systemd would mount the CPU and CPU accounting controllers
69
-	# (respectively "cpu" and "cpuacct") with "-o cpuacct,cpu"
70
-	# but on a directory called "cpu,cpuacct" (note the inversion
71
-	# in the order of the groups). This tries to work around it.
72
-
73
-	if [ "$HIER" = 'cpuacct,cpu' ]; then
74
-		ln -s "$HIER" "$CGROUP/cpu,cpuacct"
75
-	fi
76
-
77
-	# If hierarchy has multiple subsystems, in /proc/<pid>/cgroup
78
-	# we will see ":subsys1,subsys2,subsys3,name=foo:" substring,
79
-	# we need to mount it to "$CGROUP/foo" and if there were no
80
-	# name to "$CGROUP/subsys1,subsys2,subsys3", so we must create
81
-	# symlinks for docker daemon to find these subsystems:
82
-	# ln -s $CGROUP/foo $CGROUP/subsys1
83
-	# ln -s $CGROUP/subsys1,subsys2,subsys3 $CGROUP/subsys1
84
-
85
-	if [ "$SUBSYSTEMS" != "${SUBSYSTEMS//,/ }" ]; then
86
-		SUBSYSTEMS="${SUBSYSTEMS//,/ }"
87
-		for SUBSYS in $SUBSYSTEMS
88
-		do
89
-			ln -s "$CGROUP/$HIER" "$CGROUP/$SUBSYS"
90
-		done
91
-	fi
92
-done
93
-
94 35
 # Note: as I write those lines, the LXC userland tools cannot setup
95 36
 # a "sub-container" properly if the "devices" cgroup is not in its
96 37
 # own hierarchy. Let's detect this and issue a warning.