From 6f75ba0bdab3ab1f29773740611bb0ce6f9ab99c Mon Sep 17 00:00:00 2001 From: Dwight Engen Date: Wed, 17 Oct 2012 13:28:27 -0400 Subject: [PATCH] Add distro config file /etc/lxc/lxc.conf 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 Signed-off-by: Serge Hallyn --- Makefile.am | 2 +- config/Makefile.am | 9 +++++++++ config/lxc.conf.libvirt | 3 +++ config/lxc.conf.ubuntu | 3 +++ config/lxc.conf.unknown | 1 + configure.ac | 42 ++++++++++++++++++++++++++++++++++++++--- lxc.spec.in | 1 + src/lxc/lxc-create.in | 23 +++++++++------------- 8 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 config/lxc.conf.libvirt create mode 100644 config/lxc.conf.ubuntu create mode 100644 config/lxc.conf.unknown diff --git a/Makefile.am b/Makefile.am index 05a03f499..f99ad1ca3 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 783ba738d..f9949a78c 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.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 index 000000000..71286190e --- /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.ubuntu b/config/lxc.conf.ubuntu new file mode 100644 index 000000000..d2ac1678a --- /dev/null +++ b/config/lxc.conf.ubuntu @@ -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 index 000000000..16fa9d662 --- /dev/null +++ b/config/lxc.conf.unknown @@ -0,0 +1 @@ +lxc.network.type=empty diff --git a/configure.ac b/configure.ac index ae04fe2fc..82effb3bd 100644 --- a/configure.ac +++ b/configure.ac @@ -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}") diff --git a/lxc.spec.in b/lxc.spec.in index e55c69a56..414b51c2f 100644 --- a/lxc.spec.in +++ b/lxc.spec.in @@ -91,6 +91,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 79c67d627..949edbe2c 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 -- 2.39.2