mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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) Docker-DCO-1.1-Signed-off-by: Tianon Gravi <admwiggin@gmail.com> (github: crosbymichael)
This commit is contained in:
parent
0ab7b6952a
commit
2b3fdf2344
4 changed files with 123 additions and 76 deletions
|
@ -14,13 +14,15 @@
|
||||||
# VMs, bare metal, OpenStack clusters, public clouds and more.
|
# VMs, bare metal, OpenStack clusters, public clouds and more.
|
||||||
### END INIT INFO
|
### END INIT INFO
|
||||||
|
|
||||||
|
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
||||||
|
|
||||||
BASE=$(basename $0)
|
BASE=$(basename $0)
|
||||||
|
|
||||||
|
# modify these in /etc/default/$BASE (/etc/default/docker)
|
||||||
DOCKER=/usr/bin/$BASE
|
DOCKER=/usr/bin/$BASE
|
||||||
DOCKER_PIDFILE=/var/run/$BASE.pid
|
DOCKER_PIDFILE=/var/run/$BASE.pid
|
||||||
DOCKER_OPTS=
|
DOCKER_OPTS=
|
||||||
|
DOCKER_DESC="Docker"
|
||||||
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
|
||||||
|
|
||||||
# Get lsb functions
|
# Get lsb functions
|
||||||
. /lib/lsb/init-functions
|
. /lib/lsb/init-functions
|
||||||
|
@ -30,8 +32,8 @@ if [ -f /etc/default/$BASE ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
|
# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
|
||||||
if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | /bin/grep -q upstart; then
|
if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then
|
||||||
log_failure_msg "Docker is managed via upstart, try using service $BASE $1"
|
log_failure_msg "$DOCKER_DESC is managed via upstart, try using service $BASE $1"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -43,7 +45,7 @@ fi
|
||||||
|
|
||||||
fail_unless_root() {
|
fail_unless_root() {
|
||||||
if [ "$(id -u)" != '0' ]; then
|
if [ "$(id -u)" != '0' ]; then
|
||||||
log_failure_msg "Docker must be run as root"
|
log_failure_msg "$DOCKER_DESC must be run as root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -51,21 +53,37 @@ fail_unless_root() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
fail_unless_root
|
fail_unless_root
|
||||||
log_begin_msg "Starting Docker: $BASE"
|
|
||||||
mount | grep cgroup >/dev/null || mount -t cgroup none /sys/fs/cgroup 2>/dev/null
|
if ! grep -q cgroup /proc/mounts; then
|
||||||
|
# rough approximation of cgroupfs-mount
|
||||||
|
mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
|
||||||
|
for sys in $(cut -d' ' -f1 /proc/cgroups); do
|
||||||
|
mkdir -p /sys/fs/cgroup/$sys
|
||||||
|
if ! mount -n -t cgroup -o $sys cgroup /sys/fs/cgroup/$sys 2>/dev/null; then
|
||||||
|
rmdir /sys/fs/cgroup/$sys 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
touch /var/log/docker.log
|
||||||
|
chgrp docker /var/log/docker.log
|
||||||
|
|
||||||
|
log_begin_msg "Starting $DOCKER_DESC: $BASE"
|
||||||
start-stop-daemon --start --background \
|
start-stop-daemon --start --background \
|
||||||
|
--no-close \
|
||||||
--exec "$DOCKER" \
|
--exec "$DOCKER" \
|
||||||
--pidfile "$DOCKER_PIDFILE" \
|
--pidfile "$DOCKER_PIDFILE" \
|
||||||
-- -d -p "$DOCKER_PIDFILE" \
|
-- \
|
||||||
$DOCKER_OPTS
|
-d -p "$DOCKER_PIDFILE" \
|
||||||
|
$DOCKER_OPTS \
|
||||||
|
> /var/log/docker.log 2>&1
|
||||||
log_end_msg $?
|
log_end_msg $?
|
||||||
;;
|
;;
|
||||||
|
|
||||||
stop)
|
stop)
|
||||||
fail_unless_root
|
fail_unless_root
|
||||||
log_begin_msg "Stopping Docker: $BASE"
|
log_begin_msg "Stopping $DOCKER_DESC: $BASE"
|
||||||
start-stop-daemon --stop \
|
start-stop-daemon --stop --pidfile "$DOCKER_PIDFILE"
|
||||||
--pidfile "$DOCKER_PIDFILE"
|
|
||||||
log_end_msg $?
|
log_end_msg $?
|
||||||
;;
|
;;
|
||||||
|
|
13
contrib/init/sysvinit-debian/docker.default
Normal file
13
contrib/init/sysvinit-debian/docker.default
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Docker Upstart and SysVinit configuration file
|
||||||
|
|
||||||
|
# Customize location of Docker binary (especially for development testing).
|
||||||
|
#DOCKER="/usr/local/bin/docker"
|
||||||
|
|
||||||
|
# Use DOCKER_OPTS to modify the daemon startup options.
|
||||||
|
#DOCKER_OPTS="-dns 8.8.8.8 -dns 8.8.4.4"
|
||||||
|
|
||||||
|
# If you need Docker to use an HTTP proxy, it can also be specified here.
|
||||||
|
#export http_proxy="http://127.0.0.1:3128/"
|
||||||
|
|
||||||
|
# This is also a handy place to tweak where Docker's temporary files go.
|
||||||
|
#export TMPDIR="/mnt/bigdrive/docker-tmp"
|
|
@ -1,15 +1,26 @@
|
||||||
description "Docker daemon"
|
description "Docker daemon"
|
||||||
|
|
||||||
start on filesystem and started lxc-net
|
start on filesystem
|
||||||
stop on runlevel [!2345]
|
stop on runlevel [!2345]
|
||||||
|
|
||||||
respawn
|
respawn
|
||||||
|
|
||||||
script
|
script
|
||||||
|
# modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)
|
||||||
DOCKER=/usr/bin/$UPSTART_JOB
|
DOCKER=/usr/bin/$UPSTART_JOB
|
||||||
DOCKER_OPTS=
|
DOCKER_OPTS=
|
||||||
if [ -f /etc/default/$UPSTART_JOB ]; then
|
if [ -f /etc/default/$UPSTART_JOB ]; then
|
||||||
. /etc/default/$UPSTART_JOB
|
. /etc/default/$UPSTART_JOB
|
||||||
fi
|
fi
|
||||||
|
if ! grep -q cgroup /proc/mounts; then
|
||||||
|
# rough approximation of cgroupfs-mount
|
||||||
|
mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
|
||||||
|
for sys in $(cut -d' ' -f1 /proc/cgroups); do
|
||||||
|
mkdir -p /sys/fs/cgroup/$sys
|
||||||
|
if ! mount -n -t cgroup -o $sys cgroup /sys/fs/cgroup/$sys 2>/dev/null; then
|
||||||
|
rmdir /sys/fs/cgroup/$sys 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
"$DOCKER" -d $DOCKER_OPTS
|
"$DOCKER" -d $DOCKER_OPTS
|
||||||
end script
|
end script
|
||||||
|
|
|
@ -29,42 +29,36 @@ bundle_ubuntu() {
|
||||||
cp contrib/udev/80-docker.rules $DIR/etc/udev/rules.d/
|
cp contrib/udev/80-docker.rules $DIR/etc/udev/rules.d/
|
||||||
|
|
||||||
# Include our init scripts
|
# Include our init scripts
|
||||||
mkdir -p $DIR/etc
|
mkdir -p $DIR/etc/init
|
||||||
cp -R contrib/init/upstart $DIR/etc/init
|
cp contrib/init/upstart/docker.conf $DIR/etc/init/
|
||||||
cp -R contrib/init/sysvinit $DIR/etc/init.d
|
mkdir -p $DIR/etc/init.d
|
||||||
mkdir -p $DIR/lib/systemd
|
cp contrib/init/sysvinit-debian/docker $DIR/etc/init.d/
|
||||||
cp -R contrib/init/systemd $DIR/lib/systemd/system
|
|
||||||
|
|
||||||
mkdir -p $DIR/etc/default
|
mkdir -p $DIR/etc/default
|
||||||
cat > $DIR/etc/default/docker <<'EOF'
|
cp contrib/init/sysvinit-debian/docker.default $DIR/etc/default/docker
|
||||||
# Docker Upstart and SysVinit configuration file
|
mkdir -p $DIR/lib/systemd/system
|
||||||
|
cp contrib/init/systemd/docker.service $DIR/lib/systemd/system/
|
||||||
# Customize location of Docker binary (especially for development testing).
|
|
||||||
#DOCKER="/usr/local/bin/docker"
|
|
||||||
|
|
||||||
# Use DOCKER_OPTS to modify the daemon startup options.
|
|
||||||
#DOCKER_OPTS="-dns 8.8.8.8"
|
|
||||||
|
|
||||||
# If you need Docker to use an HTTP proxy, it can also be specified here.
|
|
||||||
#export http_proxy=http://127.0.0.1:3128/
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# Copy the binary
|
# Copy the binary
|
||||||
# This will fail if the binary bundle hasn't been built
|
# This will fail if the binary bundle hasn't been built
|
||||||
mkdir -p $DIR/usr/bin
|
mkdir -p $DIR/usr/bin
|
||||||
# Copy the binary
|
|
||||||
# This will fail if the binary bundle hasn't been built
|
|
||||||
cp $DEST/../binary/docker-$VERSION $DIR/usr/bin/docker
|
cp $DEST/../binary/docker-$VERSION $DIR/usr/bin/docker
|
||||||
|
|
||||||
# Generate postinst/prerm/postrm scripts
|
# Generate postinst/prerm/postrm scripts
|
||||||
cat > /tmp/postinst <<'EOF'
|
cat > $DEST/postinst <<'EOF'
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
getent group docker > /dev/null || groupadd --system docker || true
|
if [ "$1" = 'configure' ] && [ -z "$2" ]; then
|
||||||
|
if ! getent group docker > /dev/null; then
|
||||||
|
groupadd --system docker
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! { [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; }; then
|
||||||
|
# we only need to do this if upstart isn't in charge
|
||||||
update-rc.d docker defaults > /dev/null || true
|
update-rc.d docker defaults > /dev/null || true
|
||||||
|
fi
|
||||||
if [ -n "$2" ]; then
|
if [ -n "$2" ]; then
|
||||||
_dh_action=restart
|
_dh_action=restart
|
||||||
else
|
else
|
||||||
|
@ -74,7 +68,7 @@ service docker $_dh_action 2>/dev/null || true
|
||||||
|
|
||||||
#DEBHELPER#
|
#DEBHELPER#
|
||||||
EOF
|
EOF
|
||||||
cat > /tmp/prerm <<'EOF'
|
cat > $DEST/prerm <<'EOF'
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
set -u
|
set -u
|
||||||
|
@ -83,7 +77,7 @@ service docker stop 2>/dev/null || true
|
||||||
|
|
||||||
#DEBHELPER#
|
#DEBHELPER#
|
||||||
EOF
|
EOF
|
||||||
cat > /tmp/postrm <<'EOF'
|
cat > $DEST/postrm <<'EOF'
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
set -u
|
set -u
|
||||||
|
@ -101,15 +95,18 @@ fi
|
||||||
#DEBHELPER#
|
#DEBHELPER#
|
||||||
EOF
|
EOF
|
||||||
# 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
|
# 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
|
||||||
chmod +x /tmp/postinst /tmp/prerm
|
chmod +x $DEST/postinst $DEST/prerm $DEST/postrm
|
||||||
|
|
||||||
(
|
(
|
||||||
|
# switch directories so we create *.deb in the right folder
|
||||||
cd $DEST
|
cd $DEST
|
||||||
|
|
||||||
|
# create lxc-docker-VERSION package
|
||||||
fpm -s dir -C $DIR \
|
fpm -s dir -C $DIR \
|
||||||
--name lxc-docker-$VERSION --version $PKGVERSION \
|
--name lxc-docker-$VERSION --version $PKGVERSION \
|
||||||
--after-install /tmp/postinst \
|
--after-install $DEST/postinst \
|
||||||
--before-remove /tmp/prerm \
|
--before-remove $DEST/prerm \
|
||||||
--after-remove /tmp/postrm \
|
--after-remove $DEST/postrm \
|
||||||
--architecture "$PACKAGE_ARCHITECTURE" \
|
--architecture "$PACKAGE_ARCHITECTURE" \
|
||||||
--prefix / \
|
--prefix / \
|
||||||
--depends iptables \
|
--depends iptables \
|
||||||
|
@ -117,6 +114,7 @@ EOF
|
||||||
--deb-recommends ca-certificates \
|
--deb-recommends ca-certificates \
|
||||||
--deb-recommends git \
|
--deb-recommends git \
|
||||||
--deb-recommends xz-utils \
|
--deb-recommends xz-utils \
|
||||||
|
--deb-suggests cgroup-lite \
|
||||||
--description "$PACKAGE_DESCRIPTION" \
|
--description "$PACKAGE_DESCRIPTION" \
|
||||||
--maintainer "$PACKAGE_MAINTAINER" \
|
--maintainer "$PACKAGE_MAINTAINER" \
|
||||||
--conflicts docker \
|
--conflicts docker \
|
||||||
|
@ -134,6 +132,9 @@ EOF
|
||||||
--config-files /etc/default/docker \
|
--config-files /etc/default/docker \
|
||||||
--deb-compression gz \
|
--deb-compression gz \
|
||||||
-t deb .
|
-t deb .
|
||||||
|
# TODO replace "Suggests: cgroup-lite" with "Recommends: cgroupfs-mount | cgroup-lite" once cgroupfs-mount is available
|
||||||
|
|
||||||
|
# create empty lxc-docker wrapper package
|
||||||
fpm -s empty \
|
fpm -s empty \
|
||||||
--name lxc-docker --version $PKGVERSION \
|
--name lxc-docker --version $PKGVERSION \
|
||||||
--architecture "$PACKAGE_ARCHITECTURE" \
|
--architecture "$PACKAGE_ARCHITECTURE" \
|
||||||
|
@ -145,6 +146,10 @@ EOF
|
||||||
--deb-compression gz \
|
--deb-compression gz \
|
||||||
-t deb
|
-t deb
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# clean up after ourselves so we have a clean output directory
|
||||||
|
rm $DEST/postinst $DEST/prerm $DEST/postrm
|
||||||
|
rm -r $DIR
|
||||||
}
|
}
|
||||||
|
|
||||||
bundle_ubuntu
|
bundle_ubuntu
|
||||||
|
|
Loading…
Add table
Reference in a new issue