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

Serge Hallyn serge.hallyn at canonical.com
Thu Oct 18 15:34:16 UTC 2012


Quoting Dwight Engen (dwight.engen at oracle.com):
> 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>

Thanks much for doing this, Dwight.  I'm pushing this to my github
tree.  I do have one question below (which, if I'm not wrong, would
only result in a 1-line patch).

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  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 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..f9949a7 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) $@

Should the lxc.conf be deleted at make clean?  Else, this probably needs to
be 'cp -f' or 'make; make clean; make' will fail the last make?  (haven't
tried)

> +
>  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 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.ubuntu b/config/lxc.conf.ubuntu
> new file mode 100644
> index 0000000..d2ac167
> --- /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 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..657d4e6 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 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