]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Add distro config file /etc/lxc/lxc.conf
authorDwight Engen <dwight.engen@oracle.com>
Wed, 17 Oct 2012 17:28:27 +0000 (13:28 -0400)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 12 Nov 2012 18:18:32 +0000 (13:18 -0500)
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@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Makefile.am
config/Makefile.am
config/lxc.conf.libvirt [new file with mode: 0644]
config/lxc.conf.ubuntu [new file with mode: 0644]
config/lxc.conf.unknown [new file with mode: 0644]
configure.ac
lxc.spec.in
src/lxc/lxc-create.in

index 05a03f49968bd2e9e744338cd2372f32bedebf26..f99ad1ca3b1d6e21e3f48e68c727500bf023cf84 100644 (file)
@@ -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
 
index 783ba738d9fef6ef8803cba43dd43c2d4d370cf6..f9949a78c92f9cabeadfc54ded4f2c414d53c4e6 100644 (file)
@@ -1,2 +1,11 @@
+configdir = $(sysconfdir)/lxc
+config_DATA = lxc.conf
+conffile = @LXC_CONFFILE@
+
+EXTRA_DIST = lxc.conf.ubuntu 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.libvirt b/config/lxc.conf.libvirt
new file mode 100644 (file)
index 0000000..7128619
--- /dev/null
@@ -0,0 +1,3 @@
+lxc.network.type=veth
+lxc.network.link=virbr0
+lxc.network.flags=up
diff --git a/config/lxc.conf.ubuntu b/config/lxc.conf.ubuntu
new file mode 100644 (file)
index 0000000..d2ac167
--- /dev/null
@@ -0,0 +1,3 @@
+lxc.network.type=veth
+lxc.network.link=lxcbr0
+lxc.network.flags=up
diff --git a/config/lxc.conf.unknown b/config/lxc.conf.unknown
new file mode 100644 (file)
index 0000000..16fa9d6
--- /dev/null
@@ -0,0 +1 @@
+lxc.network.type=empty
index ae04fe2fcaf2e095a18c12ef0a2ff59e827fc7b2..82effb3bdc510ccac9c1f9df66d507abf0bca079 100644 (file)
@@ -12,10 +12,45 @@ AM_PROG_CC_C_O
 AC_GNU_SOURCE
 AC_CHECK_PROG(SETCAP, setcap, yes, no, $PATH$PATH_SEPARATOR/sbin)
 
-if test -f /etc/debian_version; then
-    osname="debian"
+AC_MSG_CHECKING([host distribution])
+AC_ARG_WITH(distro, AS_HELP_STRING([--with-distro=DISTRO], [Specify the Linux distribution to target: One of redhat, oracle, fedora, suse, gentoo, debian, arch, slackware, paldo, mandriva or pardus]))
+if test "z$with_distro" = "z"; then
+       with_distro=`lsb_release -is`
 fi
-AM_CONDITIONAL([HAVE_DEBIAN], [test x"$osname" == xdebian])
+if test "z$with_distro" = "z"; then
+       AC_CHECK_FILE(/etc/redhat-release,with_distro="redhat")
+       AC_CHECK_FILE(/etc/oracle-release,with_distro="oracle")
+       AC_CHECK_FILE(/etc/fedora-release,with_distro="fedora")
+       AC_CHECK_FILE(/etc/SuSE-release,with_distro="suse")
+       AC_CHECK_FILE(/etc/gentoo-release,with_distro="gentoo")
+       AC_CHECK_FILE(/etc/debian_version,with_distro="debian")
+       AC_CHECK_FILE(/etc/arch-release,with_distro="arch")
+       AC_CHECK_FILE(/etc/slackware-version,with_distro="slackware")
+       AC_CHECK_FILE(/etc/frugalware-release,with_distro="frugalware")
+       AC_CHECK_FILE(/etc/mandrakelinux-release, with_distro="mandriva")
+       AC_CHECK_FILE(/etc/mandriva-release,with_distro="mandriva")
+       AC_CHECK_FILE(/etc/pardus-release,with_distro="pardus")
+fi
+with_distro=`echo ${with_distro} | tr '[[:upper:]]' '[[:lower:]]'`
+
+if test "z$with_distro" = "z"; then
+       with_distro="unknown"
+fi
+case $with_distro in
+       ubuntu)
+               conffile=lxc.conf.ubuntu
+               ;;
+       redhat|fedora|oracle|oracleserver)
+               conffile=lxc.conf.libvirt
+               ;;
+       *)
+               echo -n "Linux distribution network config unknown, defaulting to lxc.network.type = empty"
+               conffile=lxc.conf.unknown
+               ;;
+esac
+AC_MSG_RESULT([$with_distro])
+
+AM_CONDITIONAL([HAVE_DEBIAN], [test x"$with_distro" = "xdebian" -o x"$with_distro" = "xubuntu"])
 
 AC_ARG_ENABLE([rpath],
        [AC_HELP_STRING([--disable-rpath], [do not set rpath in executables])],
@@ -111,6 +146,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}")
index e55c69a56e20b24519780e464bec68a0abf3642a..414b51c2f9ca58d2d2a5e4cbab94809c4afee203 100644 (file)
@@ -91,6 +91,7 @@ rm -rf %{buildroot}
 %{_mandir}/*
 %{_datadir}/doc/*
 %{_datadir}/lxc/*
+%{_sysconfdir}/lxc/*
 
 %files libs
 %defattr(-,root,root)
index 79c67d627c9b32cc0fe80c792e2a9cf25cfd0a92..949edbe2c2ab72911391b812c4e4f653a4214e5c 100644 (file)
@@ -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