From 19ca5c408ad14bef81d3e785f0cb4a70e95db467 Mon Sep 17 00:00:00 2001 From: Bruce Ashfield Date: Wed, 8 Apr 2015 13:26:22 -0400 Subject: docker: add sysvinit script Adding a basic sysvinit script to docker .. for those that still use sysvinit! Signed-off-by: Bruce Ashfield --- recipes-containers/docker/docker_git.bb | 10 ++- recipes-containers/docker/files/docker.init | 126 ++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 recipes-containers/docker/files/docker.init diff --git a/recipes-containers/docker/docker_git.bb b/recipes-containers/docker/docker_git.bb index 225745a5..a683840d 100644 --- a/recipes-containers/docker/docker_git.bb +++ b/recipes-containers/docker/docker_git.bb @@ -22,6 +22,7 @@ SRCREV = "2243e32cbbf1c9809c262a7376d34ca43a7a36dc" SRC_URI = "\ git://github.com/docker/docker.git \ file://docker.service \ + file://docker.init \ file://hi.Dockerfile \ " @@ -97,11 +98,15 @@ do_compile() { go install github.com/docker/libcontainer/nsinit/ } -inherit systemd +inherit systemd update-rc.d SYSTEMD_PACKAGES = "${@base_contains('DISTRO_FEATURES','systemd','${PN}','',d)}" SYSTEMD_SERVICE_${PN} = "${@base_contains('DISTRO_FEATURES','systemd','docker.service','',d)}" +INITSCRIPT_PACKAGES += "${@base_contains('DISTRO_FEATURES','sysvinit','${PN}','',d)}" +INITSCRIPT_NAME_${PN} = "${@base_contains('DISTRO_FEATURES','sysvinit','docker.init','',d)}" +INITSCRIPT_PARAMS_${PN} = "${OS_DEFAULT_INITSCRIPT_PARAMS}" + do_install() { mkdir -p ${D}/${bindir} cp ${S}/bundles/${DOCKER_VERSION}-dev/dynbinary/docker-${DOCKER_VERSION}-dev \ @@ -114,6 +119,9 @@ do_install() { install -m 644 ${S}/contrib/init/systemd/docker.* ${D}/${systemd_unitdir}/system # replaces one copied from above with one that uses the local registry for a mirror install -m 644 ${WORKDIR}/docker.service ${D}/${systemd_unitdir}/system + else + install -d ${D}${sysconfdir}/init.d + install -m 0755 ${WORKDIR}/docker.init ${D}${sysconfdir}/init.d/docker.init fi cp ${S}/vendor/bin/nsinit ${D}/${bindir} diff --git a/recipes-containers/docker/files/docker.init b/recipes-containers/docker/files/docker.init new file mode 100644 index 00000000..9c01c758 --- /dev/null +++ b/recipes-containers/docker/files/docker.init @@ -0,0 +1,126 @@ +#!/bin/sh +# +# /etc/rc.d/init.d/docker +# +# Daemon for docker.com +# +# chkconfig: 2345 95 95 +# description: Daemon for docker.com + +### BEGIN INIT INFO +# Provides: docker +# Required-Start: $network cgconfig +# Required-Stop: +# Should-Start: +# Should-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: start and stop docker +# Description: Daemon for docker.com +### END INIT INFO + +# Source function library. +. /etc/init.d/functions + +prog="docker" +unshare=/usr/bin/unshare +exec="/usr/bin/$prog" +pidfile="/var/run/$prog.pid" +lockfile="/var/lock/subsys/$prog" +logfile="/var/log/$prog" + +[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog + +start() { + [ -x $exec ] || exit 5 + + check_for_cleanup + + if ! [ -f $pidfile ]; then + printf "Starting $prog:\t" + echo "\n$(date)\n" >> $logfile + "$unshare" -m -- $exec -d $other_args &>> $logfile & + pid=$! + touch $lockfile + # wait up to 10 seconds for the pidfile to exist. see + # https://github.com/docker/docker/issues/5359 + tries=0 + while [ ! -f $pidfile -a $tries -lt 10 ]; do + sleep 1 + tries=$((tries + 1)) + done + success + echo + else + failure + echo + printf "$pidfile still exists...\n" + exit 7 + fi +} + +stop() { + echo -n $"Stopping $prog: " + killproc $prog + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +restart() { + stop + start +} + +reload() { + restart +} + +force_reload() { + restart +} + +rh_status() { + status -p $pidfile $prog +} + +rh_status_q() { + rh_status >/dev/null 2>&1 +} + + +check_for_cleanup() { + if [ -f ${pidfile} ]; then + /bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile} + fi +} + +case "$1" in + start) + $1 + ;; + stop) + $1 + ;; + restart) + $1 + ;; + reload) + $1 + ;; + force-reload) + force_reload + ;; + status) + status + ;; + condrestart|try-restart) + restart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" + exit 2 +esac + +exit $? -- cgit v1.2.3-54-g00ecf