Commit 420dfb59 by Dwight Engen Committed by Serge Hallyn

add lxc-autostart support for sysv init systems

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: 's avatarDwight Engen <dwight.engen@oracle.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent 0a83cbbb
...@@ -70,6 +70,50 @@ AC_MSG_RESULT([$with_distro]) ...@@ -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([HAVE_DEBIAN], [test x"$with_distro" = "xdebian" -o x"$with_distro" = "xubuntu"])
AM_CONDITIONAL([DISTRO_UBUNTU], [test "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 # Allow disabling rpath
AC_ARG_ENABLE([rpath], AC_ARG_ENABLE([rpath],
[AC_HELP_STRING([--enable-rpath], [set rpath in executables [default=no]])], [AC_HELP_STRING([--enable-rpath], [set rpath in executables [default=no]])],
...@@ -610,6 +654,7 @@ cat << EOF ...@@ -610,6 +654,7 @@ cat << EOF
Environment: Environment:
- compiler: $CC - compiler: $CC
- distribution: $with_distro - distribution: $with_distro
- init script type: $init_script
- rpath: $enable_rpath - rpath: $enable_rpath
- GnuTLS: $enable_gnutls - GnuTLS: $enable_gnutls
......
...@@ -23,6 +23,17 @@ ...@@ -23,6 +23,17 @@
%global with_python %{?_with_python: 1} %{?!_with_python: 0} %global with_python %{?_with_python: 1} %{?!_with_python: 0}
%global with_lua %{?_with_lua: 1} %{?!_with_lua: 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 # RPM needs alpha/beta/rc in Release: not Version: to ensure smooth
# package upgrades from alpha->beta->rc->release. For more info see: # package upgrades from alpha->beta->rc->release. For more info see:
# http://fedoraproject.org/wiki/Packaging%3aNamingGuidelines#NonNumericRelease # http://fedoraproject.org/wiki/Packaging%3aNamingGuidelines#NonNumericRelease
...@@ -94,7 +105,8 @@ PATH=$PATH:/usr/sbin:/sbin %configure $args \ ...@@ -94,7 +105,8 @@ PATH=$PATH:/usr/sbin:/sbin %configure $args \
%if %{with_python} %if %{with_python}
--enable-python \ --enable-python \
%endif %endif
--disable-rpath --disable-rpath \
--with-init-script=%{init_script}
make %{?_smp_mflags} make %{?_smp_mflags}
%install %install
...@@ -102,11 +114,6 @@ rm -rf %{buildroot} ...@@ -102,11 +114,6 @@ rm -rf %{buildroot}
make install DESTDIR=%{buildroot} make install DESTDIR=%{buildroot}
find %{buildroot} -type f -name '*.la' -exec rm -f {} ';' 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 %clean
rm -rf %{buildroot} rm -rf %{buildroot}
...@@ -136,7 +143,11 @@ rm -rf %{buildroot} ...@@ -136,7 +143,11 @@ rm -rf %{buildroot}
%{_datadir}/lxc/* %{_datadir}/lxc/*
%config(noreplace) %{_sysconfdir}/lxc/* %config(noreplace) %{_sysconfdir}/lxc/*
/lib/systemd/system/* %if %{with_systemd}
%{_unitdir}/lxc.service
%else
%{_sysconfdir}/rc.d/init.d/lxc
%endif
%files libs %files libs
%defattr(-,root,root) %defattr(-,root,root)
...@@ -147,7 +158,9 @@ rm -rf %{buildroot} ...@@ -147,7 +158,9 @@ rm -rf %{buildroot}
%endif %endif
%{_localstatedir}/* %{_localstatedir}/*
%attr(4555,root,root) %{_libexecdir}/%{name}/lxc-init %attr(4555,root,root) %{_libexecdir}/%{name}/lxc-init
%if %{with_systemd}
%attr(555,root,root) %{_libexecdir}/%{name}/lxc-devsetup %attr(555,root,root) %{_libexecdir}/%{name}/lxc-devsetup
%endif
%if %{with_python} %if %{with_python}
%{_libdir}/python3.3/site-packages/_lxc* %{_libdir}/python3.3/site-packages/_lxc*
......
...@@ -154,7 +154,8 @@ EXTRA_DIST = \ ...@@ -154,7 +154,8 @@ EXTRA_DIST = \
lxc-devsetup \ lxc-devsetup \
lxc-ls \ lxc-ls \
lxc-top \ lxc-top \
lxc.service lxc.service \
lxc.sysvinit
if ENABLE_PYTHON if ENABLE_PYTHON
bin_SCRIPTS += lxc-device bin_SCRIPTS += lxc-device
...@@ -197,6 +198,43 @@ bin_PROGRAMS = \ ...@@ -197,6 +198,43 @@ bin_PROGRAMS = \
pkglibexec_PROGRAMS = \ pkglibexec_PROGRAMS = \
lxc-init 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 AM_LDFLAGS = -Wl,-E
if ENABLE_RPATH if ENABLE_RPATH
AM_LDFLAGS += -Wl,-rpath -Wl,$(libdir) AM_LDFLAGS += -Wl,-rpath -Wl,$(libdir)
...@@ -229,6 +267,10 @@ lxc_snapshot_SOURCES = lxc_snapshot.c ...@@ -229,6 +267,10 @@ lxc_snapshot_SOURCES = lxc_snapshot.c
lxc_usernsexec_SOURCES = lxc_usernsexec.c lxc_usernsexec_SOURCES = lxc_usernsexec.c
lxc_user_nic_SOURCES = lxc_user_nic.c network.c network.h 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 install-exec-local: install-soPROGRAMS
mkdir -p $(DESTDIR)$(datadir)/lxc mkdir -p $(DESTDIR)$(datadir)/lxc
install -c -m 644 lxc.functions $(DESTDIR)$(datadir)/lxc install -c -m 644 lxc.functions $(DESTDIR)$(datadir)/lxc
......
#!/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 $?
...@@ -145,7 +145,7 @@ install_plamo() { ...@@ -145,7 +145,7 @@ install_plamo() {
return 1 return 1
fi fi
return 0 return 0
) 200> @LOCALSTATEDIR@/lock/subsys/lxc ) 200> @LOCALSTATEDIR@/lock/subsys/lxc-plamo
} }
configure_plamo() { configure_plamo() {
...@@ -306,7 +306,7 @@ cleanup() { ...@@ -306,7 +306,7 @@ cleanup() {
rm -rf --one-file-system $dlcache $rtcache || return 1 rm -rf --one-file-system $dlcache $rtcache || return 1
echo "Done." echo "Done."
return 0 return 0
) 200> @LOCALSTATEDIR@/lock/subsys/lxc ) 200> @LOCALSTATEDIR@/lock/subsys/lxc-plamo
} }
usage() { usage() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment