]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
add lxc-autostart support for sysv init systems
authorDwight Engen <dwight.engen@oracle.com>
Tue, 31 Dec 2013 19:21:55 +0000 (14:21 -0500)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 3 Jan 2014 19:49:04 +0000 (13:49 -0600)
This change updates the way init scripts get installed so that more
than one init system can be supported. Instead of installing the
systemd service file from the spec file, it should be installed at
make install time, so that someone compiling from source also gets
the unit file installed.

Update the plamo template to use a lock file not named just
/var/lock/subsys/lxc since the presence of that file is used by
sysv init rc file to know if it should run the K01lxc script. This
also makes it consistent with the other templates which use
/var/lock/subsys/lxc-$template-name.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
configure.ac
lxc.spec.in
src/lxc/Makefile.am
src/lxc/lxc.sysvinit [new file with mode: 0755]
templates/lxc-plamo.in

index 4c5f0028e4aea2e5b01c4fce42b79e94a999751d..2d2493773621f69bd2a86dbd8975a3d815001fd8 100644 (file)
@@ -70,6 +70,50 @@ AC_MSG_RESULT([$with_distro])
 AM_CONDITIONAL([HAVE_DEBIAN], [test x"$with_distro" = "xdebian" -o x"$with_distro" = "xubuntu"])
 AM_CONDITIONAL([DISTRO_UBUNTU], [test "x$with_distro" = "xubuntu"])
 
+# Check for init system type
+AC_MSG_CHECKING([for init system type])
+AC_ARG_WITH([init-script],
+           [AC_HELP_STRING([--with-init-script@<:@=TYPE@:>@],
+                           [Type of init script to install: sysv, systemd, upstart,
+                            distro, none @<:@default=distro@:>@])],[],[with_init_script=distro])
+case "$with_init_script" in
+       sysv)
+               init_script=sysv
+               ;;
+       systemd)
+               init_script=systemd
+               ;;
+       upstart)
+               init_script=upstart
+               ;;
+       none)
+               ;;
+       distro)
+               case $with_distro in
+                       fedora)
+                               init_script=systemd
+                               ;;
+                       redhat|centos|oracle|oracleserver)
+                               init_script=sysv
+                               ;;
+                       ubuntu)
+                               init_script=upstart
+                               ;;
+                       *)
+                               echo -n "Linux distribution init system unknown, defaulting to sysv"
+                               init_script=sysv
+                               ;;
+               esac
+               ;;
+       *)
+               AC_MSG_ERROR([Unknown init system type $with_init_script])
+               ;;
+esac
+AM_CONDITIONAL([INIT_SCRIPT_SYSV], test "$init_script" = "sysv")
+AM_CONDITIONAL([INIT_SCRIPT_SYSTEMD], test "$init_script" = "systemd")
+AM_CONDITIONAL([INIT_SCRIPT_UPSTART], test "$init_script" = "upstart")
+AC_MSG_RESULT($init_script)
+
 # Allow disabling rpath
 AC_ARG_ENABLE([rpath],
        [AC_HELP_STRING([--enable-rpath], [set rpath in executables [default=no]])],
@@ -610,6 +654,7 @@ cat << EOF
 Environment:
  - compiler: $CC
  - distribution: $with_distro
+ - init script type: $init_script
  - rpath: $enable_rpath
  - GnuTLS: $enable_gnutls
 
index 6814ad70559e0aeccabab3dda79ae6c6cfb6a2a7..b977c8c9fe670f33f5e27b6cd242169cf259fc18 100644 (file)
 %global with_python %{?_with_python: 1} %{?!_with_python: 0}
 %global with_lua %{?_with_lua: 1} %{?!_with_lua: 0}
 
+# Set with_systemd on distros that use it, so we can install the service
+# file, otherwise the sysvinit script will be installed
+%if 0%{?fedora} >= 14 || 0%{?rhel} >= 7 || 0%{?suse_version} >= 1210
+%global with_systemd 1
+%define init_script systemd
+BuildRequires: systemd-units
+%else
+%global with_systemd 0
+%define init_script sysv
+%endif
+
 # RPM needs alpha/beta/rc in Release: not Version: to ensure smooth
 # package upgrades from alpha->beta->rc->release. For more info see:
 # http://fedoraproject.org/wiki/Packaging%3aNamingGuidelines#NonNumericRelease
@@ -94,7 +105,8 @@ PATH=$PATH:/usr/sbin:/sbin %configure $args \
 %if %{with_python}
   --enable-python \
 %endif
-  --disable-rpath
+  --disable-rpath \
+  --with-init-script=%{init_script}
 make %{?_smp_mflags}
 
 %install
@@ -102,11 +114,6 @@ rm -rf %{buildroot}
 make install DESTDIR=%{buildroot}
 find %{buildroot} -type f -name '*.la' -exec rm -f {} ';'
 
-# Install some of our systemd stuff...
-install -d -m 755 %{buildroot}/lib/systemd/system
-install -c -m 644 src/lxc/lxc.service %{buildroot}/lib/systemd/system
-install -c -m 755 src/lxc/lxc-devsetup %{buildroot}/%{_libexecdir}/%{name}
-
 %clean
 rm -rf %{buildroot}
 
@@ -136,7 +143,11 @@ rm -rf %{buildroot}
 %{_datadir}/lxc/*
 %config(noreplace) %{_sysconfdir}/lxc/*
 
-/lib/systemd/system/*
+%if %{with_systemd}
+%{_unitdir}/lxc.service
+%else
+%{_sysconfdir}/rc.d/init.d/lxc
+%endif
 
 %files libs
 %defattr(-,root,root)
@@ -147,7 +158,9 @@ rm -rf %{buildroot}
 %endif
 %{_localstatedir}/*
 %attr(4555,root,root) %{_libexecdir}/%{name}/lxc-init
+%if %{with_systemd}
 %attr(555,root,root) %{_libexecdir}/%{name}/lxc-devsetup
+%endif
 
 %if %{with_python}
 %{_libdir}/python3.3/site-packages/_lxc*
index 74b38e2dbbfa2ee285d3f0c5611591ccdc9465b0..c54120ab1af70a9e4bbf1144ca0f5bcb20df55cb 100644 (file)
@@ -154,7 +154,8 @@ EXTRA_DIST = \
        lxc-devsetup \
        lxc-ls \
        lxc-top \
-       lxc.service
+       lxc.service \
+       lxc.sysvinit
 
 if ENABLE_PYTHON
 bin_SCRIPTS += lxc-device
@@ -197,6 +198,43 @@ bin_PROGRAMS = \
 pkglibexec_PROGRAMS = \
        lxc-init
 
+if INIT_SCRIPT_SYSV
+install-init: lxc.sysvinit
+       $(MKDIR_P) $(DESTDIR)$(sysconfdir)/rc.d/init.d
+       $(INSTALL_SCRIPT) lxc.sysvinit $(DESTDIR)$(sysconfdir)/rc.d/init.d/lxc
+
+uninstall-init:
+       rm -f $(DESTDIR)$(sysconfdir)/rc.d/init.d/lxc
+       rmdir $(DESTDIR)$(sysconfdir)/rc.d/init.d || :
+else
+install-init:
+uninstall-init:
+endif
+
+if INIT_SCRIPT_SYSTEMD
+SYSTEMD_UNIT_DIR = /usr/lib/systemd/system
+install-systemd: lxc.service lxc-devsetup
+       $(MKDIR_P) $(DESTDIR)$(SYSTEMD_UNIT_DIR)
+       $(INSTALL_DATA) lxc.service $(DESTDIR)$(SYSTEMD_UNIT_DIR)/
+
+uninstall-systemd:
+       rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/lxc.service
+       rmdir $(DESTDIR)$(SYSTEMD_UNIT_DIR) || :
+pkglibexec_SCRIPTS = lxc-devsetup
+else
+install-systemd:
+uninstall-systemd:
+endif
+
+if INIT_SCRIPT_UPSTART
+# FIXME: install/uninstall upstart script here
+install-upstart:
+uninstall-upstart:
+else
+install-upstart:
+uninstall-upstart:
+endif
+
 AM_LDFLAGS = -Wl,-E
 if ENABLE_RPATH
 AM_LDFLAGS += -Wl,-rpath -Wl,$(libdir)
@@ -229,6 +267,10 @@ lxc_snapshot_SOURCES = lxc_snapshot.c
 lxc_usernsexec_SOURCES = lxc_usernsexec.c
 lxc_user_nic_SOURCES = lxc_user_nic.c network.c network.h
 
+install-data-local: install-init install-systemd install-upstart
+
+uninstall-local: uninstall-init uninstall-systemd uninstall-upstart
+
 install-exec-local: install-soPROGRAMS
        mkdir -p $(DESTDIR)$(datadir)/lxc
        install -c -m 644 lxc.functions $(DESTDIR)$(datadir)/lxc
diff --git a/src/lxc/lxc.sysvinit b/src/lxc/lxc.sysvinit
new file mode 100755 (executable)
index 0000000..9128187
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/sh
+#
+# lxc Start/Stop LXC autoboot containers
+#
+# chkconfig: 345 99 01
+# description: Starts/Stops all LXC containers configured for autostart.
+#
+### BEGIN INIT INFO
+# Provides: lxc
+# Default-Start: 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Bring up/down LXC autostart containers
+# Description: Bring up/down LXC autostart containers
+### END INIT INFO
+
+# Source function library.
+. /etc/init.d/functions
+
+# Check for needed utility program
+[ -x /usr/bin/lxc-autostart ] || exit 1
+
+# If libvirtd is providing the bridge, it might not be
+# immediately available, so wait a bit for it before starting
+# up the containers or else any that use the bridge will fail
+# to start
+wait_for_bridge()
+{
+    [ -f /etc/lxc/default.conf ] || { return 0; }
+
+    BRNAME=`grep lxc.network.link /etc/lxc/default.conf |awk '{print $3}'`
+    [ -n $BRNAME ] || { return 0; }
+
+    for try in `seq 1 30`; do
+       ifconfig -a |grep "^$BRNAME" >/dev/null 2>&1
+       if [ $? = 0 ]; then
+           return
+       fi
+       sleep 1
+    done
+}
+
+# See how we were called.
+case "$1" in
+  start)
+       [ ! -f /var/lock/subsys/lxc ] || { exit 0; }
+
+       # Start containers
+       wait_for_bridge
+       action $"Starting LXC containers: " /usr/bin/lxc-autostart
+       touch /var/lock/subsys/lxc
+       ;;
+  stop)
+       action $"Stopping LXC containers: " /usr/bin/lxc-autostart -s
+       rm -f /var/lock/subsys/lxc
+       ;;
+  restart|reload|force-reload)
+       $0 stop
+       $0 start
+       ;;
+  *)
+       echo $"Usage: $0 {start|stop|restart|reload|force-reload}"
+       exit 2
+esac
+exit $?
index 485f36304c87fb78b945e5b648316500fa407d4f..8705a057be5c7251b4c42655c7ae3fe8e929294d 100644 (file)
@@ -145,7 +145,7 @@ install_plamo() {
       return 1
     fi
     return 0
-  ) 200> @LOCALSTATEDIR@/lock/subsys/lxc
+  ) 200> @LOCALSTATEDIR@/lock/subsys/lxc-plamo
 }
 
 configure_plamo() {
@@ -306,7 +306,7 @@ cleanup() {
     rm -rf --one-file-system $dlcache $rtcache || return 1
     echo "Done."
     return 0
-  ) 200> @LOCALSTATEDIR@/lock/subsys/lxc
+  ) 200> @LOCALSTATEDIR@/lock/subsys/lxc-plamo
 }
 
 usage() {