Commit Graph

1197 Commits

Author SHA1 Message Date
Stéphane Graber
6a85cf9124 Install legacy scripts when built without python.
Re-introduce the old lxc-ls script and manpage under a new legacy
sub-directory.

Those will be installed in place of their python equivalent when LXC
is built without --enable-python.

Any other script ported to python should be added to those lists.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-12-04 14:01:30 -05:00
Stéphane Graber
4e7186c535 Rewrite lxc-ls in python
This rewrite is mostly compatible with the shell version.
--active and -1 still work and behave as they used to.

This adds --running, --stopped and --frozen as state filters.

A new "fancy" view is also implemented (can be used with --fancy) and
will show containers in a column-based interface with the following fields:
 - name
 - state
 - ipv4
 - ipv6
 - pid of init

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-12-04 14:00:56 -05:00
Serge Hallyn
4a85ce2ad0 lxc_conf logfile and loglevel support
Add 'lxc.logfile' and 'lxc.loglevel' config items.  Values provided on
the command line override the config items.

Have lxccontainer not set a default loglevel and logfile.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-12-04 11:38:25 -06:00
Serge Hallyn
44d397891e templates: use hardlink detection in rsync
I'm not sure whether we want this:  is -H ubiquitous?

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Michael H. Warfield <mhw@WittsEnd.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
2012-12-04 10:10:24 -06:00
Serge Hallyn
2130af2665 lxc-clone: use hardlink detection in rsync
Otherwise busybox clones have been reported to explode from
2M to 440M.

Reported-by: Rene K. Mueller <spiritdude@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Michael H. Warfield <mhw@WittsEnd.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
2012-12-04 10:10:00 -06:00
Dwight Engen
6902a6c664 Create busybox commands as symlinks instead of hardlinks
I was getting a "Too many links" error when creating a busybox container on
a btrfs file system. This change has the template create the links as
symlinks instead. It also generates the list of commands to be symlinked from
busybox itself instead of a hardcoded list in the template.

Also set the root password to root, to match what other templates do.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-12-03 10:00:30 -05:00
Stéphane Graber
1d4f064658 lxc-create: Script cleanup
- Removes the mixed tabs/spaces, replacing by standard 4 spaces indent.
 - Fix a bunch of bashisms.
 - Use shell syntax for and/or in if statements instead of the "test" syntax.
 - Improve block spacing a bit.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-12-03 09:59:17 -05:00
Stéphane Graber
fa0e6e1bf4 lxc-create: Store template information in config
Change lxc-create to add the name of the template, checksum and any parameters
to the container's configuration.
This makes it easier to debug and figure out exactly how a container was built.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-12-03 09:57:38 -05:00
Serge Hallyn
61435768cd check and warn of return value from fchdir
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-29 20:05:37 -06:00
Dwight Engen
cc423c6739 Include lxc-ubuntu when doing make dist
Removing templates/lxc-ubuntu from configure.ac makes it so that it is
not included in the tarball that make dist builds (and therefore also
breaks the rpm build).

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-29 13:32:34 -05:00
Serge Hallyn
91c3830e22 Description: run MAKEDEV console when doing lxc.autodev
mounted-dev.conf won't be running that in container's userspace as it
previously would have, so make sure that all the devices it would have
created (other than ones which lxc later finagles) get created.
To achieve this, we have to first mount /dev, then run MAKEDEV, then
run setup_autodev to populate the rest of /dev.

Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1075717

Changelog:
  v2: Use INFO rather than ERROR when makedev fails, since we won't stop the container boot.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-29 11:14:07 -06:00
Dwight Engen
5f29734f7d Fix build with --enable-tests on Fedora
When using --enable-tests on Fedora, the linker complains with:
"undefined reference to symbol sem_getvalue", which nm shows to be in
libpthread not librt. Build tested on Fedora, Oracle Linux, and Ubuntu.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-29 10:28:06 -05:00
Stéphane Graber
89573feb5b lxc-ubuntu: Fix wrong variable name
$LANGPACK_LIST was renamed to $langpacks but not all the code was updated.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-29 10:26:54 -05:00
Stéphane Graber
1e1f8eeb14 lxc-ubuntu: Fix mixed indent
Replace all remaining tabs by 8 spaces, to properly indent by 4 spaces.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-29 10:26:29 -05:00
Stéphane Graber
8e100cef8b lxc-ubuntu: Rename from lxc-ubuntu.in
lxc-ubuntu no longer uses any build time variables, therefore it can
now be simply copied to the target without any autoconf magic.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-29 10:26:26 -05:00
Stéphane Graber
fade719ed9 lxc-ubuntu: Guess a list of langpacks to install
In addition to creating the current locale in the container, also
try to scan the host and extra the list of langpacks installed there,
then pass that list to debootstrap as additional packages to install.

On distros that don't have dpkg, only language-pack-en will be installed.
The code will always ensure that language-pack-en is ALWAYS installed in the
target, similar to what Ubuntu does with its various media.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-29 10:26:23 -05:00
Stéphane Graber
18f823c1ca lxc-ubuntu: Always create the needed locales
Move some old code from the trim() function into the main configure_ubuntu
function so that we always create a locale in the container.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-29 10:26:20 -05:00
Dwight Engen
e62fa3f9ce Fix busybox template to not have extra aa_profile hunk
Both 69d66f1e and f02ce27d added the aa_profile = unconfined hunk, but only
the first was needed, maybe a merge error? The second one causes the
template to get an error on the EOF line. This essentially reverts
f02ce27d.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-29 10:18:41 -05:00
Serge Hallyn
bf555f0384 revert inadvertent un-doing of lxc-clone fix
commit 8f2c3a702a reverted a fix
for bad handling by lxc-clone of 'lxc.mount[ \t]' lines.
Fix.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-28 09:57:59 -06:00
Dwight Engen
000559b5de Oracle template: make container also boot under libvirt
This allows containers created with lxc-create to also boot under
libvirt/Virtual Machine Monitor

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-27 15:00:30 -05:00
Dwight Engen
12a50cc6ab Make config api items const
This makes it easier to write a binding, and presents a cleaner API. Use
strdupa in a few places to get mutable strings for tokenizing / parsing.
Also change the argv type in lxcapi_start and lxcapi_create to match
that of execv(3).

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-27 14:59:33 -05:00
Natanael Copa
12ad0f90c1 lxc-setuid: use POSIX shell instead of bash
Avoid getop --longoptions.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-27 10:11:14 -05:00
Natanael Copa
f910f092e5 lxc-setcap: use POSIX shell instead of bash
Avoid getopt --longoptions

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-27 10:10:49 -05:00
Dwight Engen
b45a7402bf Use autoconf LXCPATH instead of hardcoded LXCDIR
LXCDIR is only used in lxc_container_new, whereas LXCPATH is used throughout
the rest of lxc, and even in the same file as lxc_container_new (for example
create_container_dir()).

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-27 10:07:51 -05:00
Natanael Copa
7ec3fa7139 lxc-checkconfig: use POSIX shell instead of bash
- replace 'echo -e' with printf
- replace 'if [[ ... ]]' with 'if [ ... ]'
- add \ at after && and || when those are at end of line

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-27 10:04:49 -05:00
Natanael Copa
89d3558804 lxc-version: use POSIX shell instead of bash
There is no reason to depend on bash for a single echo.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-27 10:04:04 -05:00
Serge Hallyn
6b1a07ba08 fix lxc-ubuntu-cloud option parsing bugs
The -u shortopt matching --userdata was not specified, and when -L
is found shift should have been by 1 not 2 since there is no optarg.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-26 15:12:26 -05:00
Natanael Copa
b917ef7522 lxc-info: add option -t, --state-is=STATE to test for a given test
Add an option to test for a give state. This is useful for scripts.
It lets us you do thing like:

 if lxc-info --name myname --state-is RUNNING; then
   ...

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 14:29:43 -05:00
Dwight Engen
83cab6e068 Ensure argv passed by createl to create is NULL terminated
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 13:14:18 -05:00
Dwight Engen
d95db067d2 Free allocated configuration memory
Most of these were found with valgrind by repeatedly doing lxc_container_new
followed by lxc_container_put. Also free memory when config items are
re-parsed, as happens when lxcapi_set_config_item() is called. Refactored
path type config items to use a common underlying routine.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 13:13:47 -05:00
Dwight Engen
9ebb03ad4a Fix use of list item memory after free
Valgrind showed use of ->next field after item has been free()ed.
Introduce a lxc_list_for_each_safe() which allows traversal of a list
when the body of the loop may remove the currently iterated item.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 12:54:00 -05:00
Dwight Engen
2312f31b07 Fix fd leak in lxc log
lxc_log_init will leak an fd when it is called by a long running
program that may call lxc_container_new multiple times. Fix by
only opening the log if it is not already open.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 12:53:57 -05:00
Stéphane Graber
181a9be7e4 gitignore: Ignore python cache
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 12:32:56 -05:00
Stéphane Graber
2cdb945b13 python: Use builtin len() function for network interfaces
Use our own len() function for network interfaces as doing
len(container.get_config_item("lxc.network")) will fail when the
list is empty.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 12:32:50 -05:00
Stéphane Graber
bde1853954 python: PEP8 compatibility
The new version of the pep8 command is detecting more indentation
mistakes than it used to, this fixes them.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 12:32:37 -05:00
Stéphane Graber
f79d43bbe7 Remove all trailing whitespaces.
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-26 12:08:13 -05:00
Dwight Engen
c93c7b1a0b Fix checkconfig to handle kernel memory cgroup name change
The kernel config option for the memory cgroup was changed in 3.6
from CONFIG_CGROUP_MEM_RES_CTLR to CONFIG_MEMCG with commit c255a458.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-26 11:56:04 -05:00
Stéphane Graber
ad493d03fe lxc.conf.sgml.in: Fix typo
Fix a typo in the previous lxc.conf.sgml.in change.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-26 11:45:28 -05:00
Serge Hallyn
c6883f383e Add lxc.autodev
Add a container config option to mount and populate /dev in a container.

We might want to add options to specify a max size for /dev other than
the default 100k, and to specify other devices to create.  And maybe
someone can think of a better name than autodev.

Changelog: Don't error out if we couldn't mknod a /dev/ttyN.
Changelog: Describe the option in lxc.conf manpage.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 10:02:47 -06:00
Stéphane Graber
69c478daf1 python: Add new lxc-device tool
Add a new lxc-device tool which uses the new add_device() function of
the python API and lets you add a new device node to a running container.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 09:32:58 -05:00
Stéphane Graber
2a41cf5d68 python: Add add_device() function
This introduces a new add_devices() call to the python API.

Parameters:
 - path => Mandatory, path to a character or block device on the host
 - destpath => Optional, alternative path inside the container

The function will allow the node in the container's devices cgroup and
then create the entry in the container.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 09:31:52 -05:00
Natanael Copa
7858afacec lxc-create: do not use 'local'
Apparently 'local' is not POSIX. Don't use it.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-26 09:29:22 -05:00
Natanael Copa
11cbdf441d lxc-create: fix passing over first argument to template script
The e60a8164c1 introduced a bug that caused
first argument passed over to the template script get lost.

This patch fixes it.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-26 09:28:46 -05:00
Natanael Copa
e60a8164c1 lxc-create: use posix shell instead of bash
- use '[ -x /path/prog ]' instead of 'type /path/prog'
- avoid getopt --longoptions
- add \ at after && and || when those are at end of line
- make sure condition expands to empty string if variable is empty

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-21 14:36:08 -05:00
Stéphane Graber
c3752c0b59 Use clearer error message on failure to create pidfile
As suggested by Serge Hallyn on lxc-devel.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-15 10:51:09 -05:00
Natanael Copa
3114c98242 lxc-start: add option -p, --pidfile=FILE
Add option to create a pidfile for lxc-start. This is helpful for
init scripts and process monitors when running as daemon.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-15 10:50:56 -05:00
Dwight Engen
f6a8db2d94 Fix package name needed for building docs with RPM
Tested on Oracle Linux 6 and Fedora 17

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-14 10:55:06 -05:00
Frederic Crozat
f8a59e3152 ensure btrfs subvolume is removed when container creating fails
Signed-off-by: Frederic Crozat <fcrozat@suse.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-14 10:54:54 -05:00
Serge Hallyn
f62b344996 dont fail on failure to link kmsg
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-14 08:55:07 -06:00
Stéphane Graber
18c266fc4c Add the test binaries to .gitignore
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-13 19:36:05 -05:00