[packages/lxc-docker] add initscript for docker daemon

glen glen at pld-linux.org
Wed Sep 25 18:48:25 CEST 2013


commit 345101bde82214d1917a306a4af1b8431e063a15
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Wed Sep 25 19:48:15 2013 +0300

    add initscript for docker daemon

 lxc-docker.init | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lxc-docker.spec | 22 +++++++++++--
 2 files changed, 117 insertions(+), 3 deletions(-)
---
diff --git a/lxc-docker.spec b/lxc-docker.spec
index 6d70961..d24ff87 100644
--- a/lxc-docker.spec
+++ b/lxc-docker.spec
@@ -5,7 +5,7 @@
 Summary:	Docker: the Linux container engine
 Name:		lxc-docker
 Version:	0.6.1
-Release:	2
+Release:	3
 License:	Apache v2.0
 Group:		Applications/System
 Source0:	https://github.com/dotcloud/docker/archive/v%{version}.tar.gz
@@ -23,18 +23,22 @@ Source4:	https://github.com/dotcloud/tar/archive/master.tar.gz?/tar.tgz
 # $ PKG=code.google.com/p/go.net/ REV=84a4013f96e0; hg clone http://$PKG go.net && cd go.net && hg checkout $REV && cd .. && tar -cjf go.net.tar.gz2 --exclude-vcs go.net
 Source5:	go.net.tar.bz2
 # Source5-md5:	c8fd9d068430ddfa42d28d4772260eda
+Source6:	%{name}.init
 Patch0:		bash-comp-2.patch
 URL:		http://github.com/dotcloud/docker
 BuildRequires:	golang >= 1.1
+BuildRequires:	rpmbuild(macros) >= 1.228
 Requires:	iptables
 Requires:	lxc
+Requires:	rc-scripts >= 0.4.0.10
 Requires:	tar
 Requires:	uname(release) >= 3.8
 Requires:	xz
+Requires(post,preun):	/sbin/chkconfig
 # only runs on x64 hosts for now:
 # https://github.com/dotcloud/docker/issues/136
 # https://github.com/dotcloud/docker/issues/611
-ExclusiveArch	%{x8664}
+ExclusiveArch:	%{x8664}
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
 %define		bash_compdir	%{_datadir}/bash-completion/completions
@@ -98,8 +102,9 @@ unset GIT_DIR
 
 %install
 rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT{%{_bindir},%{_mandir}/man1,/var/lib/docker/{containers,graph,volumes}}
+install -d $RPM_BUILD_ROOT{%{_bindir},%{_mandir}/man1,/etc/rc.d/init.d,/var/lib/docker/{containers,graph,volumes}}
 install -p bin/docker $RPM_BUILD_ROOT%{_bindir}/lxc-docker
+install -p %{SOURCE6} $RPM_BUILD_ROOT/etc/rc.d/init.d/lxc-docker
 ln -s lxc-docker $RPM_BUILD_ROOT%{_bindir}/docker
 cp -p packaging/debian/lxc-docker.1 $RPM_BUILD_ROOT%{_mandir}/man1
 
@@ -108,12 +113,23 @@ install -d $RPM_BUILD_ROOT%{bash_compdir}
 cp -p contrib/docker.bash $RPM_BUILD_ROOT%{bash_compdir}/lxc-docker
 ln -s lxc-docker $RPM_BUILD_ROOT%{bash_compdir}/docker
 
+%post
+/sbin/chkconfig --add %{name}
+%service -n %{name} restart
+
+%preun
+if [ "$1" = "0" ]; then
+	%service -q %{name} stop
+	/sbin/chkconfig --del %{name}
+fi
+
 %clean
 rm -rf $RPM_BUILD_ROOT
 
 %files
 %defattr(644,root,root,755)
 %doc README.md CHANGELOG.md CONTRIBUTING.md FIXME LICENSE AUTHORS NOTICE MAINTAINERS
+%attr(754,root,root) /etc/rc.d/init.d/lxc-docker
 %attr(755,root,root) %{_bindir}/lxc-docker
 %attr(755,root,root) %{_bindir}/docker
 %{_mandir}/man1/lxc-docker.1*
diff --git a/lxc-docker.init b/lxc-docker.init
new file mode 100755
index 0000000..b893f01
--- /dev/null
+++ b/lxc-docker.init
@@ -0,0 +1,98 @@
+#!/bin/sh
+#
+# Linux container runtime
+#
+# chkconfig:	345 10 90
+#
+# description:	Linux container runtime
+#
+# processname:	docker
+# pidfile: /var/run/docker.pid
+#
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# Get network config
+. /etc/sysconfig/network
+
+# Check that networking is up.
+if is_yes "${NETWORKING}"; then
+	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+		msg_network_down "LXC Docker"
+		exit 1
+	fi
+else
+	exit 0
+fi
+
+# Get service config - may override defaults
+[ -f /etc/sysconfig/lxc-docker ] && . /etc/sysconfig/lxc-docker
+
+pidfile="/var/run/docker.pid"
+
+start() {
+	# Check if the service is already running?
+	if [ -f /var/lock/subsys/lxc-docker ]; then
+		msg_already_running "LXC Docker"
+		return
+	fi
+
+	msg_starting "LXC Docker"
+	daemon --fork /usr/bin/docker -d
+	RETVAL=$?
+	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/lxc-docker
+}
+
+stop() {
+	if [ ! -f /var/lock/subsys/lxc-docker ]; then
+		msg_not_running "LXC Docker"
+		return
+	fi
+
+	# Stop daemons.
+	msg_stopping "LXC Docker"
+	killproc --pidfile $pidfile docker -TERM
+	rm -f /var/lock/subsys/lxc-docker
+}
+
+condrestart() {
+	if [ ! -f /var/lock/subsys/lxc-docker ]; then
+		msg_not_running "LXC Docker"
+		RETVAL=$1
+		return
+	fi
+
+	stop
+	start
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+	start
+	;;
+  stop)
+	stop
+	;;
+  restart)
+	stop
+	start
+	;;
+  try-restart)
+	condrestart 0
+	;;
+  force-reload)
+	condrestart 7
+	;;
+  status)
+	status --pidfile $pidfile lxc-docker docker
+	RETVAL=$?
+	;;
+  *)
+	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
+	exit 3
+esac
+
+exit $RETVAL
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/lxc-docker.git/commitdiff/345101bde82214d1917a306a4af1b8431e063a15



More information about the pld-cvs-commit mailing list