Browse code

Fix a few packaging bugs, including and especially a temporary patch to our upstart script to mount cgroups properly

Docker-DCO-1.1-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon)

Tianon Gravi authored on 2014/03/10 14:16:42
Showing 5 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,114 @@
0
+#!/bin/sh
1
+
2
+### BEGIN INIT INFO
3
+# Provides:           docker
4
+# Required-Start:     $syslog $remote_fs
5
+# Required-Stop:      $syslog $remote_fs
6
+# Default-Start:      2 3 4 5
7
+# Default-Stop:       0 1 6
8
+# Short-Description:  Create lightweight, portable, self-sufficient containers.
9
+# Description:
10
+#  Docker is an open-source project to easily create lightweight, portable,
11
+#  self-sufficient containers from any application. The same container that a
12
+#  developer builds and tests on a laptop can run at scale, in production, on
13
+#  VMs, bare metal, OpenStack clusters, public clouds and more.
14
+### END INIT INFO
15
+
16
+export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
17
+
18
+BASE=$(basename $0)
19
+
20
+# modify these in /etc/default/$BASE (/etc/default/docker)
21
+DOCKER=/usr/bin/$BASE
22
+DOCKER_PIDFILE=/var/run/$BASE.pid
23
+DOCKER_OPTS=
24
+DOCKER_DESC="Docker"
25
+
26
+# Get lsb functions
27
+. /lib/lsb/init-functions
28
+
29
+if [ -f /etc/default/$BASE ]; then
30
+	. /etc/default/$BASE
31
+fi
32
+
33
+# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
34
+if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then
35
+	log_failure_msg "$DOCKER_DESC is managed via upstart, try using service $BASE $1"
36
+	exit 1
37
+fi
38
+
39
+# Check docker is present
40
+if [ ! -x $DOCKER ]; then
41
+	log_failure_msg "$DOCKER not present or not executable"
42
+	exit 1
43
+fi
44
+
45
+fail_unless_root() {
46
+	if [ "$(id -u)" != '0' ]; then
47
+		log_failure_msg "$DOCKER_DESC must be run as root"
48
+		exit 1
49
+	fi
50
+}
51
+
52
+case "$1" in
53
+	start)
54
+		fail_unless_root
55
+
56
+		if ! grep -q cgroup /proc/mounts; then
57
+			# rough approximation of cgroupfs-mount
58
+			mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
59
+			for sys in $(cut -d'	' -f1 /proc/cgroups); do
60
+				mkdir -p /sys/fs/cgroup/$sys
61
+				if ! mount -n -t cgroup -o $sys cgroup /sys/fs/cgroup/$sys 2>/dev/null; then
62
+					rmdir /sys/fs/cgroup/$sys 2>/dev/null || true
63
+				fi
64
+			done
65
+		fi
66
+
67
+		touch /var/log/docker.log
68
+		chgrp docker /var/log/docker.log
69
+
70
+		log_begin_msg "Starting $DOCKER_DESC: $BASE"
71
+		start-stop-daemon --start --background \
72
+			--no-close \
73
+			--exec "$DOCKER" \
74
+			--pidfile "$DOCKER_PIDFILE" \
75
+			-- \
76
+				-d -p "$DOCKER_PIDFILE" \
77
+				$DOCKER_OPTS \
78
+					> /var/log/docker.log 2>&1
79
+		log_end_msg $?
80
+		;;
81
+
82
+	stop)
83
+		fail_unless_root
84
+		log_begin_msg "Stopping $DOCKER_DESC: $BASE"
85
+		start-stop-daemon --stop --pidfile "$DOCKER_PIDFILE"
86
+		log_end_msg $?
87
+		;;
88
+
89
+	restart)
90
+		fail_unless_root
91
+		docker_pid=`cat "$DOCKER_PIDFILE" 2>/dev/null`
92
+		[ -n "$docker_pid" ] \
93
+			&& ps -p $docker_pid > /dev/null 2>&1 \
94
+			&& $0 stop
95
+		$0 start
96
+		;;
97
+
98
+	force-reload)
99
+		fail_unless_root
100
+		$0 restart
101
+		;;
102
+
103
+	status)
104
+		status_of_proc -p "$DOCKER_PIDFILE" "$DOCKER" docker
105
+		;;
106
+
107
+	*)
108
+		echo "Usage: $0 {start|stop|restart|status}"
109
+		exit 1
110
+		;;
111
+esac
112
+
113
+exit 0
0 114
new file mode 100644
... ...
@@ -0,0 +1,13 @@
0
+# Docker Upstart and SysVinit configuration file
1
+
2
+# Customize location of Docker binary (especially for development testing).
3
+#DOCKER="/usr/local/bin/docker"
4
+
5
+# Use DOCKER_OPTS to modify the daemon startup options.
6
+#DOCKER_OPTS="-dns 8.8.8.8 -dns 8.8.4.4"
7
+
8
+# If you need Docker to use an HTTP proxy, it can also be specified here.
9
+#export http_proxy="http://127.0.0.1:3128/"
10
+
11
+# This is also a handy place to tweak where Docker's temporary files go.
12
+#export TMPDIR="/mnt/bigdrive/docker-tmp"
0 13
deleted file mode 100755
... ...
@@ -1,96 +0,0 @@
1
-#!/bin/sh
2
-
3
-### BEGIN INIT INFO
4
-# Provides:           docker
5
-# Required-Start:     $syslog $remote_fs
6
-# Required-Stop:      $syslog $remote_fs
7
-# Default-Start:      2 3 4 5
8
-# Default-Stop:       0 1 6
9
-# Short-Description:  Create lightweight, portable, self-sufficient containers.
10
-# Description:
11
-#  Docker is an open-source project to easily create lightweight, portable,
12
-#  self-sufficient containers from any application. The same container that a
13
-#  developer builds and tests on a laptop can run at scale, in production, on
14
-#  VMs, bare metal, OpenStack clusters, public clouds and more.
15
-### END INIT INFO
16
-
17
-BASE=$(basename $0)
18
-
19
-DOCKER=/usr/bin/$BASE
20
-DOCKER_PIDFILE=/var/run/$BASE.pid
21
-DOCKER_OPTS=
22
-
23
-PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
24
-
25
-# Get lsb functions
26
-. /lib/lsb/init-functions
27
-
28
-if [ -f /etc/default/$BASE ]; then
29
-	. /etc/default/$BASE
30
-fi
31
-
32
-# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
33
-if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | /bin/grep -q upstart; then
34
-	log_failure_msg "Docker is managed via upstart, try using service $BASE $1"
35
-	exit 1
36
-fi
37
-
38
-# Check docker is present
39
-if [ ! -x $DOCKER ]; then
40
-	log_failure_msg "$DOCKER not present or not executable"
41
-	exit 1
42
-fi
43
-
44
-fail_unless_root() {
45
-	if [ "$(id -u)" != '0' ]; then
46
-		log_failure_msg "Docker must be run as root"
47
-		exit 1
48
-	fi
49
-}
50
-
51
-case "$1" in
52
-	start)
53
-		fail_unless_root
54
-		log_begin_msg "Starting Docker: $BASE"
55
-		mount | grep cgroup >/dev/null || mount -t cgroup none /sys/fs/cgroup 2>/dev/null
56
-		start-stop-daemon --start --background \
57
-			--exec "$DOCKER" \
58
-			--pidfile "$DOCKER_PIDFILE" \
59
-			-- -d -p "$DOCKER_PIDFILE" \
60
-			$DOCKER_OPTS
61
-		log_end_msg $?
62
-		;;
63
-
64
-	stop)
65
-		fail_unless_root
66
-		log_begin_msg "Stopping Docker: $BASE"
67
-		start-stop-daemon --stop \
68
-			--pidfile "$DOCKER_PIDFILE"
69
-		log_end_msg $?
70
-		;;
71
-
72
-	restart)
73
-		fail_unless_root
74
-		docker_pid=`cat "$DOCKER_PIDFILE" 2>/dev/null`
75
-		[ -n "$docker_pid" ] \
76
-			&& ps -p $docker_pid > /dev/null 2>&1 \
77
-			&& $0 stop
78
-		$0 start
79
-		;;
80
-
81
-	force-reload)
82
-		fail_unless_root
83
-		$0 restart
84
-		;;
85
-
86
-	status)
87
-		status_of_proc -p "$DOCKER_PIDFILE" "$DOCKER" docker
88
-		;;
89
-
90
-	*)
91
-		echo "Usage: $0 {start|stop|restart|status}"
92
-		exit 1
93
-		;;
94
-esac
95
-
96
-exit 0
... ...
@@ -1,15 +1,26 @@
1 1
 description "Docker daemon"
2 2
 
3
-start on filesystem and started lxc-net
3
+start on filesystem
4 4
 stop on runlevel [!2345]
5 5
 
6 6
 respawn
7 7
 
8 8
 script
9
+	# modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)
9 10
 	DOCKER=/usr/bin/$UPSTART_JOB
10 11
 	DOCKER_OPTS=
11 12
 	if [ -f /etc/default/$UPSTART_JOB ]; then
12 13
 		. /etc/default/$UPSTART_JOB
13 14
 	fi
15
+	if ! grep -q cgroup /proc/mounts; then
16
+		# rough approximation of cgroupfs-mount
17
+		mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
18
+		for sys in $(cut -d'	' -f1 /proc/cgroups); do
19
+			mkdir -p /sys/fs/cgroup/$sys
20
+			if ! mount -n -t cgroup -o $sys cgroup /sys/fs/cgroup/$sys 2>/dev/null; then
21
+				rmdir /sys/fs/cgroup/$sys 2>/dev/null || true
22
+			fi
23
+		done
24
+	fi
14 25
 	"$DOCKER" -d $DOCKER_OPTS
15 26
 end script
... ...
@@ -29,42 +29,36 @@ bundle_ubuntu() {
29 29
 	cp contrib/udev/80-docker.rules $DIR/etc/udev/rules.d/
30 30
 
31 31
 	# Include our init scripts
32
-	mkdir -p $DIR/etc
33
-	cp -R contrib/init/upstart $DIR/etc/init
34
-	cp -R contrib/init/sysvinit $DIR/etc/init.d
35
-	mkdir -p $DIR/lib/systemd
36
-	cp -R contrib/init/systemd $DIR/lib/systemd/system
37
-
32
+	mkdir -p $DIR/etc/init
33
+	cp contrib/init/upstart/docker.conf $DIR/etc/init/
34
+	mkdir -p $DIR/etc/init.d
35
+	cp contrib/init/sysvinit-debian/docker $DIR/etc/init.d/
38 36
 	mkdir -p $DIR/etc/default
39
-	cat > $DIR/etc/default/docker <<'EOF'
40
-# Docker Upstart and SysVinit configuration file
41
-
42
-# Customize location of Docker binary (especially for development testing).
43
-#DOCKER="/usr/local/bin/docker"
44
-
45
-# Use DOCKER_OPTS to modify the daemon startup options.
46
-#DOCKER_OPTS="-dns 8.8.8.8"
47
-
48
-# If you need Docker to use an HTTP proxy, it can also be specified here.
49
-#export http_proxy=http://127.0.0.1:3128/
50
-EOF
37
+	cp contrib/init/sysvinit-debian/docker.default $DIR/etc/default/docker
38
+	mkdir -p $DIR/lib/systemd/system
39
+	cp contrib/init/systemd/docker.service $DIR/lib/systemd/system/
51 40
 
52 41
 	# Copy the binary
53 42
 	# This will fail if the binary bundle hasn't been built
54 43
 	mkdir -p $DIR/usr/bin
55
-	# Copy the binary
56
-	# This will fail if the binary bundle hasn't been built
57 44
 	cp $DEST/../binary/docker-$VERSION $DIR/usr/bin/docker
58 45
 
59 46
 	# Generate postinst/prerm/postrm scripts
60
-	cat > /tmp/postinst <<'EOF'
47
+	cat > $DEST/postinst <<'EOF'
61 48
 #!/bin/sh
62 49
 set -e
63 50
 set -u
64 51
 
65
-getent group docker > /dev/null || groupadd --system docker || true
52
+if [ "$1" = 'configure' ] && [ -z "$2" ]; then
53
+	if ! getent group docker > /dev/null; then
54
+		groupadd --system docker
55
+	fi
56
+fi
66 57
 
67
-update-rc.d docker defaults > /dev/null || true
58
+if ! { [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; }; then
59
+	# we only need to do this if upstart isn't in charge
60
+	update-rc.d docker defaults > /dev/null || true
61
+fi
68 62
 if [ -n "$2" ]; then
69 63
 	_dh_action=restart
70 64
 else
... ...
@@ -74,7 +68,7 @@ service docker $_dh_action 2>/dev/null || true
74 74
 
75 75
 #DEBHELPER#
76 76
 EOF
77
-	cat > /tmp/prerm <<'EOF'
77
+	cat > $DEST/prerm <<'EOF'
78 78
 #!/bin/sh
79 79
 set -e
80 80
 set -u
... ...
@@ -83,7 +77,7 @@ service docker stop 2>/dev/null || true
83 83
 
84 84
 #DEBHELPER#
85 85
 EOF
86
-	cat > /tmp/postrm <<'EOF'
86
+	cat > $DEST/postrm <<'EOF'
87 87
 #!/bin/sh
88 88
 set -e
89 89
 set -u
... ...
@@ -101,50 +95,61 @@ fi
101 101
 #DEBHELPER#
102 102
 EOF
103 103
 	# TODO swaths of these were borrowed from debhelper's auto-inserted stuff, because we're still using fpm - we need to use debhelper instead, and somehow reconcile Ubuntu that way
104
-	chmod +x /tmp/postinst /tmp/prerm
104
+	chmod +x $DEST/postinst $DEST/prerm $DEST/postrm
105 105
 
106 106
 	(
107
+		# switch directories so we create *.deb in the right folder
107 108
 		cd $DEST
109
+
110
+		# create lxc-docker-VERSION package
108 111
 		fpm -s dir -C $DIR \
109
-		    --name lxc-docker-$VERSION --version $PKGVERSION \
110
-		    --after-install /tmp/postinst \
111
-		    --before-remove /tmp/prerm \
112
-		    --after-remove /tmp/postrm \
113
-		    --architecture "$PACKAGE_ARCHITECTURE" \
114
-		    --prefix / \
115
-		    --depends iptables \
116
-		    --deb-recommends aufs-tools \
117
-		    --deb-recommends ca-certificates \
118
-		    --deb-recommends git \
119
-		    --deb-recommends xz-utils \
120
-		    --description "$PACKAGE_DESCRIPTION" \
121
-		    --maintainer "$PACKAGE_MAINTAINER" \
122
-		    --conflicts docker \
123
-		    --conflicts docker.io \
124
-		    --conflicts lxc-docker-virtual-package \
125
-		    --provides lxc-docker \
126
-		    --provides lxc-docker-virtual-package \
127
-		    --replaces lxc-docker \
128
-		    --replaces lxc-docker-virtual-package \
129
-		    --url "$PACKAGE_URL" \
130
-		    --license "$PACKAGE_LICENSE" \
131
-		    --config-files /etc/udev/rules.d/80-docker.rules \
132
-		    --config-files /etc/init/docker.conf \
133
-		    --config-files /etc/init.d/docker \
134
-		    --config-files /etc/default/docker \
135
-		    --deb-compression gz \
136
-		    -t deb .
112
+			--name lxc-docker-$VERSION --version $PKGVERSION \
113
+			--after-install $DEST/postinst \
114
+			--before-remove $DEST/prerm \
115
+			--after-remove $DEST/postrm \
116
+			--architecture "$PACKAGE_ARCHITECTURE" \
117
+			--prefix / \
118
+			--depends iptables \
119
+			--deb-recommends aufs-tools \
120
+			--deb-recommends ca-certificates \
121
+			--deb-recommends git \
122
+			--deb-recommends xz-utils \
123
+			--deb-suggests cgroup-lite \
124
+			--description "$PACKAGE_DESCRIPTION" \
125
+			--maintainer "$PACKAGE_MAINTAINER" \
126
+			--conflicts docker \
127
+			--conflicts docker.io \
128
+			--conflicts lxc-docker-virtual-package \
129
+			--provides lxc-docker \
130
+			--provides lxc-docker-virtual-package \
131
+			--replaces lxc-docker \
132
+			--replaces lxc-docker-virtual-package \
133
+			--url "$PACKAGE_URL" \
134
+			--license "$PACKAGE_LICENSE" \
135
+			--config-files /etc/udev/rules.d/80-docker.rules \
136
+			--config-files /etc/init/docker.conf \
137
+			--config-files /etc/init.d/docker \
138
+			--config-files /etc/default/docker \
139
+			--deb-compression gz \
140
+			-t deb .
141
+		# TODO replace "Suggests: cgroup-lite" with "Recommends: cgroupfs-mount | cgroup-lite" once cgroupfs-mount is available
142
+
143
+		# create empty lxc-docker wrapper package
137 144
 		fpm -s empty \
138
-		    --name lxc-docker --version $PKGVERSION \
139
-		    --architecture "$PACKAGE_ARCHITECTURE" \
140
-		    --depends lxc-docker-$VERSION \
141
-		    --description "$PACKAGE_DESCRIPTION" \
142
-		    --maintainer "$PACKAGE_MAINTAINER" \
143
-		    --url "$PACKAGE_URL" \
144
-		    --license "$PACKAGE_LICENSE" \
145
-		    --deb-compression gz \
146
-		    -t deb
145
+			--name lxc-docker --version $PKGVERSION \
146
+			--architecture "$PACKAGE_ARCHITECTURE" \
147
+			--depends lxc-docker-$VERSION \
148
+			--description "$PACKAGE_DESCRIPTION" \
149
+			--maintainer "$PACKAGE_MAINTAINER" \
150
+			--url "$PACKAGE_URL" \
151
+			--license "$PACKAGE_LICENSE" \
152
+			--deb-compression gz \
153
+			-t deb
147 154
 	)
155
+
156
+	# clean up after ourselves so we have a clean output directory
157
+	rm $DEST/postinst $DEST/prerm $DEST/postrm
158
+	rm -r $DIR
148 159
 }
149 160
 
150 161
 bundle_ubuntu