зеркало из https://github.com/microsoft/docker.git
Merge pull request #2226 from tianon/init
Add initial init scripts library and better/safer Ubuntu packaging that works for Debian, too
This commit is contained in:
Коммит
ef5cf6c1ec
|
@ -0,0 +1,13 @@
|
||||||
|
# /etc/conf.d/docker: config file for /etc/init.d/docker
|
||||||
|
|
||||||
|
# where the docker daemon output gets piped
|
||||||
|
#DOCKER_LOGFILE="/var/log/docker.log"
|
||||||
|
|
||||||
|
# where docker's pid get stored
|
||||||
|
#DOCKER_PIDFILE="/run/docker.pid"
|
||||||
|
|
||||||
|
# where the docker daemon itself is run from
|
||||||
|
#DOCKER_BINARY="/usr/bin/docker"
|
||||||
|
|
||||||
|
# any other random options you want to pass to docker
|
||||||
|
DOCKER_OPTS=""
|
|
@ -0,0 +1,31 @@
|
||||||
|
#!/sbin/runscript
|
||||||
|
# Copyright 1999-2013 Gentoo Foundation
|
||||||
|
# Distributed under the terms of the GNU General Public License v2
|
||||||
|
# $Header: $
|
||||||
|
|
||||||
|
DOCKER_LOGFILE=${DOCKER_LOGFILE:-/var/log/${SVCNAME}.log}
|
||||||
|
DOCKER_PIDFILE=${DOCKER_PIDFILE:-/run/${SVCNAME}.pid}
|
||||||
|
DOCKER_BINARY=${DOCKER_BINARY:-/usr/bin/docker}
|
||||||
|
DOCKER_OPTS=${DOCKER_OPTS:-}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
checkpath -f -m 0644 -o root:docker "$DOCKER_LOGFILE"
|
||||||
|
|
||||||
|
ebegin "Starting docker daemon"
|
||||||
|
start-stop-daemon --start --background \
|
||||||
|
--exec "$DOCKER_BINARY" \
|
||||||
|
--pidfile "$DOCKER_PIDFILE" \
|
||||||
|
--stdout "$DOCKER_LOGFILE" \
|
||||||
|
--stderr "$DOCKER_LOGFILE" \
|
||||||
|
-- -d -p "$DOCKER_PIDFILE" \
|
||||||
|
$DOCKER_OPTS
|
||||||
|
eend $?
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
ebegin "Stopping docker daemon"
|
||||||
|
start-stop-daemon --stop \
|
||||||
|
--exec "$DOCKER_BINARY" \
|
||||||
|
--pidfile "$DOCKER_PIDFILE"
|
||||||
|
eend $?
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Easily create lightweight, portable, self-sufficient containers from any application!
|
||||||
|
Documentation=http://docs.docker.io
|
||||||
|
Requires=network.target
|
||||||
|
After=multi-user.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStartPre=/bin/mount --make-rprivate /
|
||||||
|
ExecStart=/usr/bin/docker -d
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -0,0 +1,85 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
### BEGIN INIT INFO
|
||||||
|
# Provides: docker
|
||||||
|
# Required-Start: $syslog $remote_fs
|
||||||
|
# Required-Stop: $syslog $remote_fs
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop: 0 1 6
|
||||||
|
# Short-Description: Linux container runtime
|
||||||
|
# Description: Linux container runtime
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
DOCKER=/usr/bin/docker
|
||||||
|
DOCKER_PIDFILE=/var/run/docker.pid
|
||||||
|
DOCKER_OPTS=
|
||||||
|
|
||||||
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
||||||
|
|
||||||
|
# Check lxc-docker is present
|
||||||
|
[ -x $DOCKER ] || (log_failure_msg "docker not present"; exit 1)
|
||||||
|
|
||||||
|
# Get lsb functions
|
||||||
|
. /lib/lsb/init-functions
|
||||||
|
|
||||||
|
if [ -f /etc/default/lxc ]; then
|
||||||
|
. /etc/default/lxc
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = start ] && which initctl >/dev/null && initctl version | grep -q upstart; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
check_root_id ()
|
||||||
|
{
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
log_failure_msg "Docker must be run as root"; exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
check_root_id || exit 1
|
||||||
|
log_begin_msg "Starting Docker"
|
||||||
|
mount | grep cgroup >/dev/null || mount -t cgroup none /sys/fs/cgroup 2>/dev/null
|
||||||
|
start-stop-daemon --start --background $NO_CLOSE \
|
||||||
|
--exec "$DOCKER" \
|
||||||
|
--pidfile "$DOCKER_PIDFILE" \
|
||||||
|
-- -d -p "$DOCKER_PIDFILE" \
|
||||||
|
$DOCKER_OPTS
|
||||||
|
log_end_msg $?
|
||||||
|
;;
|
||||||
|
|
||||||
|
stop)
|
||||||
|
check_root_id || exit 1
|
||||||
|
log_begin_msg "Stopping Docker"
|
||||||
|
start-stop-daemon --stop \
|
||||||
|
--pidfile "$DOCKER_PIDFILE"
|
||||||
|
log_end_msg $?
|
||||||
|
;;
|
||||||
|
|
||||||
|
restart)
|
||||||
|
check_root_id || exit 1
|
||||||
|
docker_pid=`cat "$DOCKER_PIDFILE" 2>/dev/null`
|
||||||
|
[ -n "$docker_pid" ] \
|
||||||
|
&& ps -p $docker_pid > /dev/null 2>&1 \
|
||||||
|
&& $0 stop
|
||||||
|
$0 start
|
||||||
|
;;
|
||||||
|
|
||||||
|
force-reload)
|
||||||
|
check_root_id || exit 1
|
||||||
|
$0 restart
|
||||||
|
;;
|
||||||
|
|
||||||
|
status)
|
||||||
|
status_of_proc -p "$DOCKER_PIDFILE" "$DOCKER" docker
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop|restart|status}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
|
@ -0,0 +1,10 @@
|
||||||
|
description "Docker daemon"
|
||||||
|
|
||||||
|
start on filesystem and started lxc-net
|
||||||
|
stop on runlevel [!2345]
|
||||||
|
|
||||||
|
respawn
|
||||||
|
|
||||||
|
script
|
||||||
|
/usr/bin/docker -d
|
||||||
|
end script
|
|
@ -19,26 +19,17 @@ Docker is a great building block for automating distributed systems:
|
||||||
large-scale web deployments, database clusters, continuous deployment systems,
|
large-scale web deployments, database clusters, continuous deployment systems,
|
||||||
private PaaS, service-oriented architectures, etc."
|
private PaaS, service-oriented architectures, etc."
|
||||||
|
|
||||||
UPSTART_SCRIPT='description "Docker daemon"
|
|
||||||
|
|
||||||
start on filesystem and started lxc-net
|
|
||||||
stop on runlevel [!2345]
|
|
||||||
|
|
||||||
respawn
|
|
||||||
|
|
||||||
script
|
|
||||||
/usr/bin/docker -d
|
|
||||||
end script
|
|
||||||
'
|
|
||||||
|
|
||||||
# Build docker as an ubuntu package using FPM and REPREPRO (sue me).
|
# Build docker as an ubuntu package using FPM and REPREPRO (sue me).
|
||||||
# bundle_binary must be called first.
|
# bundle_binary must be called first.
|
||||||
bundle_ubuntu() {
|
bundle_ubuntu() {
|
||||||
DIR=$DEST/build
|
DIR=$DEST/build
|
||||||
|
|
||||||
# Generate an upstart config file (ubuntu-specific)
|
# Include our init scripts
|
||||||
mkdir -p $DIR/etc/init
|
mkdir -p $DIR/etc
|
||||||
echo "$UPSTART_SCRIPT" > $DIR/etc/init/docker.conf
|
cp -R contrib/init/upstart $DIR/etc/init
|
||||||
|
cp -R contrib/init/sysvinit $DIR/etc/init.d
|
||||||
|
mkdir -p $DIR/lib/systemd
|
||||||
|
cp -R contrib/init/systemd $DIR/lib/systemd/system
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -47,29 +38,40 @@ bundle_ubuntu() {
|
||||||
# This will fail if the binary bundle hasn't been built
|
# 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 postinstall/prerm scripts
|
# Generate postinst/prerm scripts
|
||||||
cat >/tmp/postinstall <<EOF
|
cat >/tmp/postinst <<'EOF'
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
/sbin/stop docker || true
|
service docker stop || true
|
||||||
/bin/grep -q "^docker:" /etc/group || /usr/sbin/addgroup --system docker || true
|
grep -q '^docker:' /etc/group || groupadd --system docker || true
|
||||||
/sbin/start docker
|
service docker start
|
||||||
EOF
|
EOF
|
||||||
cat >/tmp/prerm <<EOF
|
cat >/tmp/prerm <<'EOF'
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
/sbin/stop docker || true
|
service docker stop || true
|
||||||
/usr/sbin/delgroup docker || true
|
|
||||||
|
case "$1" in
|
||||||
|
purge|remove|abort-install)
|
||||||
|
groupdel docker || true
|
||||||
|
;;
|
||||||
|
|
||||||
|
upgrade|failed-upgrade|abort-upgrade)
|
||||||
|
# don't touch docker group
|
||||||
|
;;
|
||||||
|
esac
|
||||||
EOF
|
EOF
|
||||||
chmod +x /tmp/postinstall /tmp/prerm
|
chmod +x /tmp/postinst /tmp/prerm
|
||||||
|
|
||||||
(
|
(
|
||||||
cd $DEST
|
cd $DEST
|
||||||
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/postinstall \
|
--after-install /tmp/postinst \
|
||||||
--before-remove /tmp/prerm \
|
--before-remove /tmp/prerm \
|
||||||
--architecture "$PACKAGE_ARCHITECTURE" \
|
--architecture "$PACKAGE_ARCHITECTURE" \
|
||||||
--prefix / \
|
--prefix / \
|
||||||
--depends lxc --depends aufs-tools \
|
--depends lxc \
|
||||||
|
--depends aufs-tools \
|
||||||
|
--depends iptables \
|
||||||
--description "$PACKAGE_DESCRIPTION" \
|
--description "$PACKAGE_DESCRIPTION" \
|
||||||
--maintainer "$PACKAGE_MAINTAINER" \
|
--maintainer "$PACKAGE_MAINTAINER" \
|
||||||
--conflicts lxc-docker-virtual-package \
|
--conflicts lxc-docker-virtual-package \
|
||||||
|
@ -80,6 +82,7 @@ EOF
|
||||||
--url "$PACKAGE_URL" \
|
--url "$PACKAGE_URL" \
|
||||||
--vendor "$PACKAGE_VENDOR" \
|
--vendor "$PACKAGE_VENDOR" \
|
||||||
--config-files /etc/init/docker.conf \
|
--config-files /etc/init/docker.conf \
|
||||||
|
--config-files /etc/init.d/docker \
|
||||||
-t deb .
|
-t deb .
|
||||||
mkdir empty
|
mkdir empty
|
||||||
fpm -s dir -C empty \
|
fpm -s dir -C empty \
|
||||||
|
@ -90,7 +93,6 @@ EOF
|
||||||
--maintainer "$PACKAGE_MAINTAINER" \
|
--maintainer "$PACKAGE_MAINTAINER" \
|
||||||
--url "$PACKAGE_URL" \
|
--url "$PACKAGE_URL" \
|
||||||
--vendor "$PACKAGE_VENDOR" \
|
--vendor "$PACKAGE_VENDOR" \
|
||||||
--config-files /etc/init/docker.conf \
|
|
||||||
-t deb .
|
-t deb .
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче