[lxc-devel] [PATCH 5/5] Add distro config file /etc/lxc/lxc.conf

Dwight Engen dwight.engen at oracle.com
Mon Oct 15 13:42:33 UTC 2012


This allows a distro to put the distro specific default network
configuration (for example bridge device, link type), or other lxc
configuration in the case that -f is not passed by the user to
lxc-create, in which case lxc-create will use the distro conf file as
the basis for the containers config.

Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
---
 Makefile.am             |    2 +-
 config/Makefile.am      |    9 +++++++++
 config/lxc.conf.debian  |    3 +++
 config/lxc.conf.libvirt |    3 +++
 config/lxc.conf.unknown |    1 +
 configure.ac            |   25 +++++++++++++++++++++++++
 lxc.spec.in             |    1 +
 src/lxc/lxc-create.in   |   23 +++++++++--------------
 8 files changed, 52 insertions(+), 15 deletions(-)
 create mode 100644 config/lxc.conf.debian
 create mode 100644 config/lxc.conf.libvirt
 create mode 100644 config/lxc.conf.unknown

diff --git a/Makefile.am b/Makefile.am
index c66ecc6..2f7606f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@
 
 ACLOCAL_AMFLAGS = -I config
 
-SUBDIRS = src templates doc
+SUBDIRS = config src templates doc
 DIST_SUBDIRS = config src templates doc
 EXTRA_DIST = autogen.sh lxc.spec CONTRIBUTING MAINTAINERS ChangeLog
 
diff --git a/config/Makefile.am b/config/Makefile.am
index 783ba73..6c39d3c 100644
--- a/config/Makefile.am
+++ b/config/Makefile.am
@@ -1,2 +1,11 @@
+configdir = $(sysconfdir)/lxc
+config_DATA = lxc.conf
+conffile = @LXC_CONFFILE@
+
+EXTRA_DIST = lxc.conf.debian lxc.conf.libvirt lxc.conf.unknown
+
+lxc.conf:
+	cp $(conffile) $@
+
 distclean:
 	@$(RM) -f compile config.guess config.sub depcomp install-sh ltmain.sh missing Makefile.in Makefile
diff --git a/config/lxc.conf.debian b/config/lxc.conf.debian
new file mode 100644
index 0000000..d2ac167
--- /dev/null
+++ b/config/lxc.conf.debian
@@ -0,0 +1,3 @@
+lxc.network.type=veth
+lxc.network.link=lxcbr0
+lxc.network.flags=up
diff --git a/config/lxc.conf.libvirt b/config/lxc.conf.libvirt
new file mode 100644
index 0000000..7128619
--- /dev/null
+++ b/config/lxc.conf.libvirt
@@ -0,0 +1,3 @@
+lxc.network.type=veth
+lxc.network.link=virbr0
+lxc.network.flags=up
diff --git a/config/lxc.conf.unknown b/config/lxc.conf.unknown
new file mode 100644
index 0000000..16fa9d6
--- /dev/null
+++ b/config/lxc.conf.unknown
@@ -0,0 +1 @@
+lxc.network.type=empty
diff --git a/configure.ac b/configure.ac
index b9a0d65..9f1e669 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,10 +12,34 @@ AM_PROG_CC_C_O
 AC_GNU_SOURCE
 AC_CHECK_PROG(SETCAP, setcap, yes, no, $PATH$PATH_SEPARATOR/sbin)
 
+# Make sure to test for fedora first since it has both fedora-release
+# and redhat-release
 if test -f /etc/debian_version; then
     osname="debian"
+elif test -f /etc/oracle-release; then
+    osname="oracle"
+elif test -f /etc/fedora-release; then
+    osname="fedora"
+elif test -f /etc/redhat-release; then
+    osname="redhat"
 fi
+
 AM_CONDITIONAL([HAVE_DEBIAN], [test x"$osname" == xdebian])
+AM_CONDITIONAL([HAVE_ORACLE], [test x"$osname" == xoracle])
+AM_CONDITIONAL([HAVE_FEDORA], [test x"$osname" == xfedora])
+AM_CONDITIONAL([HAVE_REDHAT], [test x"$osname" == xredhat])
+
+case $osname in
+	debian)
+		conffile=lxc.conf.debian
+		;;
+	oracle|redhat|fedora)
+		conffile=lxc.conf.libvirt
+		;;
+	*)
+		conffile=lxc.conf.unknown
+		;;
+esac
 
 AC_ARG_ENABLE([rpath],
 	[AC_HELP_STRING([--disable-rpath], [do not set rpath in executables])],
@@ -111,6 +135,7 @@ AC_ARG_WITH([rootfs-path],
 		[lxc rootfs mount point]
 	)], [], [with_rootfs_path=['${libdir}/lxc/rootfs']])
 
+AS_AC_EXPAND(LXC_CONFFILE, $conffile)
 AS_AC_EXPAND(LXC_GENERATE_DATE, "$(date)")
 AS_AC_EXPAND(LXCPATH, "${with_config_path}")
 AS_AC_EXPAND(LXCROOTFSMOUNT, "${with_rootfs_path}")
diff --git a/lxc.spec.in b/lxc.spec.in
index e14eff6..24d3ded 100644
--- a/lxc.spec.in
+++ b/lxc.spec.in
@@ -93,6 +93,7 @@ rm -rf %{buildroot}
 %{_mandir}/*
 %{_datadir}/doc/*
 %{_datadir}/lxc/*
+%{_sysconfdir}/lxc/*
 
 %files libs
 %defattr(-,root,root)
diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
index 79c67d6..949edbe 100644
--- a/src/lxc/lxc-create.in
+++ b/src/lxc/lxc-create.in
@@ -260,16 +260,18 @@ trap cleanup HUP INT TERM
 mkdir -p $lxc_path/$lxc_name
 
 if [ -z "$lxc_config" ]; then
-    touch $lxc_path/$lxc_name/config
-else
-    if [ ! -r "$lxc_config" ]; then
-	echo "$(basename $0): '$lxc_config' configuration file not found" >&2
-	exit 1
-    fi
+    lxc_config="@SYSCONFDIR@/lxc/lxc.conf"
+    echo
+    echo "$(basename $0): No config file specified, using the default config $lxc_config"
+fi
 
-    cp $lxc_config $lxc_path/$lxc_name/config
+if [ ! -r "$lxc_config" ]; then
+    echo "$(basename $0): '$lxc_config' configuration file not found" >&2
+    exit 1
 fi
 
+cp $lxc_config $lxc_path/$lxc_name/config
+
 if [ -n "$custom_rootfs" ]; then
 	if grep -q "lxc.rootfs" $lxc_path/$lxc_name/config ; then
 		echo "configuration file already specifies a lxc.rootfs"
@@ -295,13 +297,6 @@ if [ ! -z $lxc_template ]; then
         cleanup
     fi
 
-    if [ -z "$lxc_config" ]; then
-	echo "Note: Usually the template option is called with a configuration"
-	echo "file option too, mostly to configure the network."
-	echo "For more information look at lxc.conf (5)"
-	echo
-    fi
-
     ${templatedir}/lxc-$lxc_template --path=$lxc_path/$lxc_name --name=$lxc_name $*
     if [ $? -ne 0 ]; then
         echo "$(basename $0): failed to execute template '$lxc_template'" >&2
-- 
1.7.1





More information about the lxc-devel mailing list