Files
linuxkit/alpine/packages/docker/etc/init.d/docker
Justin Cormack 155676ee21 Do not try to run metrics proxy when not configured
Failure test case was not correct; printed a (harmless) error message
that was confusing.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
2017-02-09 13:58:03 +00:00

150 lines
4.3 KiB
Plaintext
Executable File

#!/sbin/openrc-run
depend()
{
after transfused
}
start()
{
ebegin "Starting Docker"
# check if overriding Docker with a dev bundle
if mobyconfig exists bundle
then
bundle=$(mobyconfig get bundle)
[ -n "$bundle" -a -d "$bundle" -a -h "$bundle/binary-client/docker" ] && \
export PATH=$bundle/binary-client:$bundle/binary-daemon:$PATH && \
printf "Overriding Docker with provided bundle: $bundle\n"
fi
command="${DOCKER_BINARY:-dockerd}"
pidfile="/run/docker.pid"
# mount /run shared eg for volume drivers
mount --make-shared /run
# create cgroups mount for systemd containers
if [ ! -d /sys/fs/cgroup/systemd ]
then
mkdir -p /sys/fs/cgroup/systemd
mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
fi
# Only start with networking on cloud editions
DOCKER_OPTS="${DOCKER_OPTS} -H unix:///var/run/docker.sock"
# On desktop editions, force swarm advertise address to be on eth0
# Currently we do not support multi node swarm on these editions
# for cloud plartforms the init scripts set this up
case "$(mobyplatform)" in
windows|mac)
DOCKER_OPTS="${DOCKER_OPTS} --swarm-default-advertise-addr=eth0"
;;
esac
# some config is always in /etc/docker cannot specify alternative eg certs
mkdir -p /etc/docker
if mobyconfig exists etc/docker
then
for f in $(mobyconfig find etc/docker)
do
mkdir -p $(dirname $f)
mobyconfig get $f > $f
done
fi
[ -f /etc/docker/daemon.json ] || printf '{}' > /etc/docker/daemon.json
if mobyconfig exists network
then
NETWORK_MODE="$(mobyconfig get network | tr -d '[[:space:]]')"
NATIVE_PORT_FORWARDING="$(mobyconfig get native/port-forwarding | tr -d '[[:space:]]')"
if [ "${NETWORK_MODE}" = "slirp" -o "${NATIVE_PORT_FORWARDING}" = "true" ]; then
if dockerd --help | grep -q -- --userland-proxy-path; then
DOCKER_OPTS="${DOCKER_OPTS} --userland-proxy-path /usr/bin/slirp-proxy"
else
cp /usr/bin/slirp-proxy /usr/bin/docker-proxy
fi
fi
fi
if mobyconfig exists proxy
then
export http_proxy="$(mobyconfig get proxy/http)"
export https_proxy="$(mobyconfig get proxy/https)"
export no_proxy="$(mobyconfig get proxy/exclude)"
fi
# Set Docker to debug debug if not specified in daemon.json
cat /etc/docker/daemon.json | jq -e 'has("debug")' > /dev/null || DOCKER_OPTS="${DOCKER_OPTS} --debug"
# Set experimental=true if not specified in daemon.json and on 1.13+
if dockerd --help | grep -q -- --experimental
then
cat /etc/docker/daemon.json | jq -e 'has("experimental")' > /dev/null || DOCKER_OPTS="${DOCKER_OPTS} --experimental"
fi
# On GCP, send logs to Google Cloud Logging
# Disabled because of https://github.com/docker/docker/issues/29344
# [ $(mobyplatform) = "gcp" ] && DOCKER_OPTS="${DOCKER_OPTS} --log-driver=gcplogs"
# choose storage driver
if ! $(cat /etc/docker/daemon.json | jq -e '."storage-driver"' > /dev/null)
then
STORAGE_DRIVER="overlay2"
[ -d /var/lib/docker/aufs ] && grep -q aufs /proc/filesystems && STORAGE_DRIVER="aufs"
DOCKER_OPTS="${DOCKER_OPTS} --storage-driver ${STORAGE_DRIVER}"
fi
# set ulimits as high as possible
ulimit -n 1048576
ulimit -p unlimited
# set locked memory higher for varnish
ulimit -l 82000
DOCKER_LOGFILE="/var/log/docker.log"
case "$(mobyplatform)" in
windows|mac)
# Allow iptables to be overriden
export PATH=/usr/local/sbin:$PATH
;;
esac
start-stop-daemon --start --quiet \
--background \
--startas /bin/sh \
--pidfile ${pidfile} \
-- -c "exec ${command} --pidfile=${pidfile} ${DOCKER_OPTS} 2>&1 | logger -p local0.info"
ewaitfile 20 ${pidfile} /var/run/docker.sock /var/run/docker/libcontainerd/docker-containerd.sock
# On desktop forward metrics to host if enabled in daemon.json
case "$(mobyplatform)" in
windows|mac)
METRICS_ADDR=$(cat /etc/docker/daemon.json | jq -e -r '."metrics-addr"')
if [ $? -eq 0 ]
then
METRICS_IP="$(echo "$METRICS_ADDR" | cut -d: -f1)"
METRICS_PORT="$(echo "$METRICS_ADDR" | cut -d: -f2)"
/usr/bin/slirp-proxy -proto tcp -host-ip 0.0.0.0 -host-port "$METRICS_PORT" -container-ip "$METRICS_IP" -container-port "$METRICS_PORT" -i -no-local-ip &
fi
;;
esac
eend $? "Failed to start docker"
}
stop()
{
# stop docker
einfo "Stopping docker"
pidfile="/run/docker.pid"
start-stop-daemon --stop --quiet --pidfile ${pidfile} --retry 15
return 0
}