From 9e4d782d8f1bb51bcd7e5196fa6bec3b335a744a Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 4 Oct 2013 07:59:06 -0600 Subject: [PATCH] Add POSIX shell version of host_integration/manager.go in the style of hack/make.sh Rename host_integration to host-integration for consistency Upstream-commit: 7cf1877098edb7d4874509a338f663d550ef0ede Component: engine --- .../Dockerfile.dev | 0 .../Dockerfile.min | 0 .../manager.go | 0 .../contrib/host-integration/manager.sh | 53 +++++++++++++++++++ .../contrib/host-integration/manager/systemd | 20 +++++++ .../contrib/host-integration/manager/upstart | 15 ++++++ 6 files changed, 88 insertions(+) rename components/engine/contrib/{host_integration => host-integration}/Dockerfile.dev (100%) rename components/engine/contrib/{host_integration => host-integration}/Dockerfile.min (100%) rename components/engine/contrib/{host_integration => host-integration}/manager.go (100%) create mode 100755 components/engine/contrib/host-integration/manager.sh create mode 100755 components/engine/contrib/host-integration/manager/systemd create mode 100755 components/engine/contrib/host-integration/manager/upstart diff --git a/components/engine/contrib/host_integration/Dockerfile.dev b/components/engine/contrib/host-integration/Dockerfile.dev similarity index 100% rename from components/engine/contrib/host_integration/Dockerfile.dev rename to components/engine/contrib/host-integration/Dockerfile.dev diff --git a/components/engine/contrib/host_integration/Dockerfile.min b/components/engine/contrib/host-integration/Dockerfile.min similarity index 100% rename from components/engine/contrib/host_integration/Dockerfile.min rename to components/engine/contrib/host-integration/Dockerfile.min diff --git a/components/engine/contrib/host_integration/manager.go b/components/engine/contrib/host-integration/manager.go similarity index 100% rename from components/engine/contrib/host_integration/manager.go rename to components/engine/contrib/host-integration/manager.go diff --git a/components/engine/contrib/host-integration/manager.sh b/components/engine/contrib/host-integration/manager.sh new file mode 100755 index 0000000000..fecf4bf64b --- /dev/null +++ b/components/engine/contrib/host-integration/manager.sh @@ -0,0 +1,53 @@ +#!/bin/sh +set -e + +usage() { + echo >&2 "usage: $0 [-a author] [-d description] container [manager]" + echo >&2 " ie: $0 -a 'John Smith' 4ec9612a37cd systemd" + echo >&2 " ie: $0 -d 'Super Cool System' 4ec9612a37cd # defaults to upstart" + exit 1 +} + +auth='' +desc='' +have_auth= +have_desc= +while getopts a:d: opt; do + case "$opt" in + a) + auth="$OPTARG" + have_auth=1 + ;; + d) + desc="$OPTARG" + have_desc=1 + ;; + esac +done +shift $(($OPTIND - 1)) + +[ $# -ge 1 -a $# -le 2 ] || usage + +cid="$1" +script="${2:-upstart}" +if [ ! -e "manager/$script" ]; then + echo >&2 "Error: manager type '$script' is unknown (PRs always welcome!)." + echo >&2 'The currently supported types are:' + echo >&2 " $(cd manager && echo *)" + exit 1 +fi + +# TODO https://github.com/dotcloud/docker/issues/734 (docker inspect formatting) +#if command -v docker > /dev/null 2>&1; then +# image="$(docker inspect -f '{{.Image}}' "$cid")" +# if [ "$image" ]; then +# if [ -z "$have_auth" ]; then +# auth="$(docker inspect -f '{{.Author}}' "$image")" +# fi +# if [ -z "$have_desc" ]; then +# desc="$(docker inspect -f '{{.Comment}}' "$image")" +# fi +# fi +#fi + +exec "manager/$script" "$cid" "$auth" "$desc" diff --git a/components/engine/contrib/host-integration/manager/systemd b/components/engine/contrib/host-integration/manager/systemd new file mode 100755 index 0000000000..0431b3ced4 --- /dev/null +++ b/components/engine/contrib/host-integration/manager/systemd @@ -0,0 +1,20 @@ +#!/bin/sh +set -e + +cid="$1" +auth="$2" +desc="$3" + +cat <<-EOF + [Unit] + Description=$desc + Author=$auth + After=docker.service + + [Service] + ExecStart=/usr/bin/docker start -a $cid + ExecStop=/usr/bin/docker stop -t 2 $cid + + [Install] + WantedBy=local.target +EOF diff --git a/components/engine/contrib/host-integration/manager/upstart b/components/engine/contrib/host-integration/manager/upstart new file mode 100755 index 0000000000..af90f1fddd --- /dev/null +++ b/components/engine/contrib/host-integration/manager/upstart @@ -0,0 +1,15 @@ +#!/bin/sh +set -e + +cid="$1" +auth="$2" +desc="$3" + +cat <<-EOF + description "$(echo "$desc" | sed 's/"/\\"/g')" + author "$(echo "$auth" | sed 's/"/\\"/g')" + start on filesystem and started lxc-net and started docker + stop on runlevel [!2345] + respawn + exec /usr/bin/docker start -a "$cid" +EOF