[lxc-devel] A few fixes for lxc-fedora template
Hi, I was setting up a Fedora container on my Ubuntu 11.10 system, but ran into some problems with the lxc-fedora template. I tried with the latest version from the git master, but it also needed some small fixes to get it working. So here are the fixes that I did. Hopefully someone else also finds these useful. -- Tuomas Suutari -- The demand for IT networking professionals continues to grow, and the demand for specialized networking skills is growing even more rapidly. Take a complimentary Learning@Cisco Self-Assessment and learn about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 3/3] lxc-fedora.in: Fix fetching of the fedora-release rpm
The hardcoded URL seems to be broken and 404 error was not checked. Now the mirror is selected from mirrorlist (instead of hardcoding to funet.fi) and fetch errors are checked. Also added a retry loop (with 3 tries) to find a working mirror, since some of the mirrors are not OK. Signed-off-by: Tuomas Suutari --- templates/lxc-fedora.in | 26 -- 1 files changed, 24 insertions(+), 2 deletions(-) diff --git a/templates/lxc-fedora.in b/templates/lxc-fedora.in index 1e8fff2..e7f42a6 100644 --- a/templates/lxc-fedora.in +++ b/templates/lxc-fedora.in @@ -115,8 +115,30 @@ download_fedora() echo "Downloading fedora minimal ..." YUM="yum --installroot $INSTALL_ROOT -y --nogpgcheck" PKG_LIST="yum initscripts passwd rsyslog vim-minimal dhclient chkconfig rootfiles policycoreutils" - RELEASE_URL="http://ftp.funet.fi/pub/mirrors/fedora.redhat.com/pub/fedora/linux/releases/$release/Everything/$arch/os/Packages/fedora-release-$release-1.noarch.rpm"; -curl $RELEASE_URL > $INSTALL_ROOT/fedora-release-$release.noarch.rpm + MIRRORLIST_URL="http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$release&arch=$arch"; + +DOWNLOAD_OK=no +for trynumber in 1 2 3; do +[ $trynumber != 1 ] && echo "Trying again..." +MIRROR_URL=$(curl -s -S -f "$MIRRORLIST_URL" | head -n2 | tail -n1) +if [ $? -ne 0 ] || [ -z "$MIRROR_URL" ]; then +echo "Failed to get a mirror" +continue +fi +RELEASE_URL="$MIRROR_URL/Packages/fedora-release-$release-1.noarch.rpm" +echo "Fetching from $RELEASE_URL" +curl -f "$RELEASE_URL" > $INSTALL_ROOT/fedora-release-$release.noarch.rpm +if [ $? -ne 0 ]; then +echo "Failed to download fedora release rpm" +continue +fi +DOWNLOAD_OK=yes +break +done +if [ $DOWNLOAD_OK != yes ]; then +echo "Aborting" +return 1 +fi mkdir -p $INSTALL_ROOT/var/lib/rpm rpm --root $INSTALL_ROOT --initdb -- 1.7.5.4 -- The demand for IT networking professionals continues to grow, and the demand for specialized networking skills is growing even more rapidly. Take a complimentary Learning@Cisco Self-Assessment and learn about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 1/3] lxc-fedora.in: Add missing default release variable
The text says that 14 is default, but release=14 was not set anywhere in the script. Signed-off-by: Tuomas Suutari --- templates/lxc-fedora.in |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/templates/lxc-fedora.in b/templates/lxc-fedora.in index d35600a..8588aef 100644 --- a/templates/lxc-fedora.in +++ b/templates/lxc-fedora.in @@ -317,6 +317,7 @@ if [ -z "$release" ]; then release=$(cat /etc/fedora-release |awk '/^Fedora/ {print $3}') else echo "This is not a fedora host and release missing, defaulting to 14. use -R|--release to specify release" +release=14 fi fi -- 1.7.5.4 -- The demand for IT networking professionals continues to grow, and the demand for specialized networking skills is growing even more rapidly. Take a complimentary Learning@Cisco Self-Assessment and learn about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 2/3] lxc-fedora.in: Use i386 instead of i686
There is no i686 variant of Fedora, but Ubuntu seems to return i686 from the arch command. Signed-off-by: Tuomas Suutari --- templates/lxc-fedora.in |4 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/templates/lxc-fedora.in b/templates/lxc-fedora.in index 8588aef..1e8fff2 100644 --- a/templates/lxc-fedora.in +++ b/templates/lxc-fedora.in @@ -36,6 +36,10 @@ lxc_network_link=virbr0 # is this fedora? [ -f /etc/fedora-release ] && is_fedora=true +if [ "$arch" = "i686" ]; then +arch=i386 +fi + configure_fedora() { -- 1.7.5.4 -- The demand for IT networking professionals continues to grow, and the demand for specialized networking skills is growing even more rapidly. Take a complimentary Learning@Cisco Self-Assessment and learn about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 0/3] The poor man's attach
Often people want to launch a command in an already running container. This can be achieved with the lxc-attach command, provided you have a patched kernel with full setns() support. For those who won't rebuild a kernel, we introduce the lxc-rexec command to be used in place of lxc-attach. The principle is to embed a minimal unix socket server in lxc-init that launch commands when asked to by a lxc-rexec client. For the moment, this feature only works for application containers started with lxc-execute. Some more work would be needed to have something similar for system containers (and by the way, system containers with network support may rely on rsh-like services to do the trick). The first two patches add a mainloop and logging features to lxc-init, and the last patch brings lxc-rexec. --- Greg Kurz (3): lxc: introduce lxc-rexec lxc-init: use lxc logging infrastructure lxc-init: use lxc_mainloop configure.ac |1 doc/Makefile.am |1 doc/lxc-rexec.sgml.in | 151 ++ src/lxc/Makefile.am |7 - src/lxc/arguments.h |3 src/lxc/error.c | 23 ++ src/lxc/error.h |3 src/lxc/execute.c | 66 ++ src/lxc/execute.h | 28 +++ src/lxc/lxc.h |1 src/lxc/lxc_execute.c |3 src/lxc/lxc_init.c| 511 ++--- src/lxc/lxc_rexec.c | 337 13 files changed, 1014 insertions(+), 121 deletions(-) create mode 100644 doc/lxc-rexec.sgml.in create mode 100644 src/lxc/execute.h create mode 100644 src/lxc/lxc_rexec.c -- Greg -- The demand for IT networking professionals continues to grow, and the demand for specialized networking skills is growing even more rapidly. Take a complimentary Learning@Cisco Self-Assessment and learn about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel
[lxc-devel] [PATCH 1/3] lxc-init: use lxc_mainloop
The goal here is to be able to multiplex several event sources in lxc-init. It will be a lot easier to add I/O driven features: for example, a rexec-like service to start extra commands in a container. Signed-off-by: Greg Kurz Signed-off-by: Cedric Le Goater --- src/lxc/error.c| 23 ++ src/lxc/error.h|3 + src/lxc/lxc_init.c | 206 3 files changed, 137 insertions(+), 95 deletions(-) diff --git a/src/lxc/error.c b/src/lxc/error.c index 5ecfbac..e0ba96a 100644 --- a/src/lxc/error.c +++ b/src/lxc/error.c @@ -57,3 +57,26 @@ extern int lxc_error_set_and_log(int pid, int status) return ret; } + +int lxc_error_set_and_log_siginfo(siginfo_t *siginfo) +{ + int ret = 0; + + if (siginfo->si_code == CLD_EXITED) { + if (siginfo->si_status) { + INFO("child <%d> ended on error (%d)", +siginfo->si_pid, siginfo->si_status); + ret = siginfo->si_status; + } + } else if (siginfo->si_code == CLD_KILLED) { + INFO("child <%d> ended on signal (%d)", +siginfo->si_pid, siginfo->si_signo); + ret = siginfo->si_signo + 128; + } else if (siginfo->si_code == CLD_DUMPED) { + INFO("child <%d> dumped core on signal (%d)", +siginfo->si_pid, siginfo->si_signo); + ret = siginfo->si_signo + 128; + } + + return ret; +} diff --git a/src/lxc/error.h b/src/lxc/error.h index ef25fc3..4684ab5 100644 --- a/src/lxc/error.h +++ b/src/lxc/error.h @@ -23,6 +23,9 @@ #ifndef __lxc_error_h #define __lxc_error_h +#include + extern int lxc_error_set_and_log(int pid, int status); +extern int lxc_error_set_and_log_siginfo(siginfo_t *siginfo); #endif diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c index a534b51..17704cd 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -30,6 +30,7 @@ #include #include #include +#include #define _GNU_SOURCE #include @@ -37,6 +38,7 @@ #include "caps.h" #include "error.h" #include "utils.h" +#include "mainloop.h" lxc_log_define(lxc_init, lxc); @@ -47,23 +49,91 @@ static struct option options[] = { { 0, 0, 0, 0 }, }; -static int was_interrupted = 0; +static pid_t child_pid; +static int shutting_down; +static int exit_status; +static int orphan; -int main(int argc, char *argv[]) +static int handle_child(void) { + for(;;) { + siginfo_t siginfo; + + siginfo.si_pid = 0; + + if (waitid(P_ALL, -1, &siginfo, WEXITED|WNOHANG) < 0) { + /* ECHILD means we're the last process */ + if (errno != ECHILD) + ERROR("failed to wait child : %s", + strerror(errno)); + return 1; + } + + /* No process exited */ + if (!siginfo.si_pid) + return 0; + + /* reset timer each time a process exited */ + if (shutting_down) + alarm(1); + + /* +* keep the exit code of started application +* (not wrapped pid) and continue to wait for +* the end of the orphan group. +*/ + if ((siginfo.si_pid != child_pid) || orphan) + continue; + + orphan = 1; - void interrupt_handler(int sig) - { - if (!was_interrupted) - was_interrupted = sig; + exit_status = + lxc_error_set_and_log_siginfo(&siginfo); } +} - pid_t pid; +static int handle_signal(int fd, void* data, struct lxc_epoll_descr *descr) +{ + struct signalfd_siginfo siginfo; + + /* If we get woken up, we have at least one siginfo to read: no need +* to check for errors. +*/ + read(fd, &siginfo, sizeof(siginfo)); + + switch (siginfo.ssi_signo) { + case SIGTERM: + if (!shutting_down) { + shutting_down = 1; + kill(-1, SIGTERM); + alarm(1); + } + break; + + case SIGALRM: + kill(-1, SIGKILL); + break; + + case SIGCHLD: + return handle_child(); + break; + + default: + kill(child_pid, siginfo.ssi_signo); + break; + } + + return 0; +} + +int main(int argc, char *argv[]) +{ int nbargs = 0; int err = -1; char **aargv; - sigset_t mask, omask; - int i, shutdown = 0; + sigset_t mask; + struct lxc_epoll_descr mainloop_descr; + int signal_fd; while (1) { int ret = getopt_long_only(argc, argv, "", options, NULL
[lxc-devel] [PATCH 3/3] lxc: introduce lxc-rexec
The lxc-rexec command connects to the lxc-init process on an AF_UNIX socket to spawn commands inside the container. Signals are forwarded from lxc-rexec to the command and the exit code is sent back to lxc-rexec. The command also runs in its own session with its own ctty. Multiple commands can be attached to the container. Caveats : - environment and current dir is not propagated - the container exits only when the last attached command dies - attachement between containers is possible Signed-off-by: Greg Kurz Signed-off-by: Cedric Le Goater --- configure.ac |1 doc/Makefile.am |1 doc/lxc-rexec.sgml.in | 151 ++ src/lxc/Makefile.am |7 + src/lxc/arguments.h |3 src/lxc/execute.c | 44 ++ src/lxc/execute.h | 28 src/lxc/lxc_init.c| 267 ++- src/lxc/lxc_rexec.c | 337 + 9 files changed, 833 insertions(+), 6 deletions(-) create mode 100644 doc/lxc-rexec.sgml.in create mode 100644 src/lxc/execute.h create mode 100644 src/lxc/lxc_rexec.c diff --git a/configure.ac b/configure.ac index 6fa8c4a..e7c0044 100644 --- a/configure.ac +++ b/configure.ac @@ -107,6 +107,7 @@ AC_CONFIG_FILES([ doc/lxc-create.sgml doc/lxc-destroy.sgml doc/lxc-execute.sgml + doc/lxc-rexec.sgml doc/lxc-start.sgml doc/lxc-checkpoint.sgml doc/lxc-restart.sgml diff --git a/doc/Makefile.am b/doc/Makefile.am index 8530ee9..dc2b728 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -10,6 +10,7 @@ man_MANS = \ lxc-create.1 \ lxc-destroy.1 \ lxc-execute.1 \ + lxc-rexec.1 \ lxc-start.1 \ lxc-stop.1 \ lxc-checkpoint.1 \ diff --git a/doc/lxc-rexec.sgml.in b/doc/lxc-rexec.sgml.in new file mode 100644 index 000..aa3cc9d --- /dev/null +++ b/doc/lxc-rexec.sgml.in @@ -0,0 +1,151 @@ + + + + +]> + + + + @LXC_GENERATE_DATE@ + + +lxc-rexec +1 + + + +lxc-rexec + + + spawn a command into a container + + + + + + lxc-rexec -n name + -- + command + + + + +Description + + + lxc-rexec runs the specified + command within the runnning container + name. + + + + The lxc-rexec command is to be used with + application containers, started by + the lxc-execute + command. lxc-execute spawns a custom init + process lxc-init which is also used to exec + processes inside the container. The launched process is + reparented to lxc-init, as a daemon. + + + The lxc-rexec command forwards received + signals to the command running inside the container and returns + its exit code with it dies. + + + + +Options + + + + -- + + + Signal the end of options and disables further option + processing. Any arguments after the -- are treated as + arguments. + + + This option is useful when you want to execute, with the + command lxc-execute, a command line + with its own options. + + + + + + + + + &commonoptions; + + +Diagnostic + + + + + The container does not exist + + + Check that the container still running. + + + + + + + + + &seealso; + + +Author +Daniel Lezcano daniel.lezc...@free.fr + + + + + + diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index 924cf1d..4215a94 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -23,7 +23,7 @@ liblxc_so_SOURCES = \ commands.c commands.h \ start.c start.h \ stop.c \ - execute.c \ + execute.c execute.h \ monitor.c monitor.h \ console.c \ freezer.c \ @@ -93,7 +93,8 @@ bin_PROGRAMS = \ lxc-unfreeze \ lxc-checkpoint \ lxc-restart \ - lxc-kill + lxc-kill \ + lxc-rexec pkglib_PROGRAMS = \ lxc-init @@ -112,6 +113,7 @@ lxc_execute_SOURCES = lxc_execute.c lxc_freeze_SOURCES = lxc_freeze.c lxc_info_SOURCES = lxc_info.c lxc_init_SOURCES = lxc_init.c +lxc_init_LDADD = -lutil -lcap -llxc lxc_monitor_SOURCES = lxc_monitor.c lxc_restart_SOURCES = lxc_restart.c lxc_start_SOURCES = lxc_start.c @@ -120,6 +122,7 @@ lxc_unfreeze_SOURCES = lxc_unfreeze.c lxc_unshare_SOURCES = lxc_unshare.c lxc_wait_SOURCES = lxc_wait.c lxc_kill_SOURCES = lxc_kill.c +lxc_rexec_SOURCES = lxc_rexec.c install-exec-local: install-soPROGRAMS mv $(DESTDIR)$(libdir)/liblxc.so $(DESTDIR)$(libdir)/liblxc.so.$(VERSION) diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h index 6a2ffc6..5574b52 100644 --- a/src/lxc/arguments.h +++ b/src/lxc/arguments.h @@ -58,6 +58,9 @@ struct lxc_arguments { /* for lxc-wait */ char *states; + /* for lxc-i
[lxc-devel] [PATCH 2/3] lxc-init: use lxc logging infrastructure
Because there are no reasons that a vital component like lxc-init doesn't log into a file. Signed-off-by: Greg Kurz Signed-off-by: Cedric Le Goater --- src/lxc/execute.c | 22 - src/lxc/lxc.h |1 + src/lxc/lxc_execute.c |3 ++ src/lxc/lxc_init.c| 62 ++--- 4 files changed, 56 insertions(+), 32 deletions(-) diff --git a/src/lxc/execute.c b/src/lxc/execute.c index 43210e2..5b52771 100644 --- a/src/lxc/execute.c +++ b/src/lxc/execute.c @@ -25,6 +25,7 @@ #include #include +#include "lxc.h" #include "log.h" #include "start.h" @@ -33,6 +34,8 @@ lxc_log_define(lxc_execute, lxc_start); struct execute_args { char *const *argv; int quiet; + char *log_file; + char *log_priority; }; static int execute_start(struct lxc_handler *handler, void* data) @@ -44,11 +47,23 @@ static int execute_start(struct lxc_handler *handler, void* data) while (my_args->argv[argc++]); - argv = malloc((argc + my_args->quiet ? 5 : 4) * sizeof(*argv)); + /* We add at most 10 strings (including the terminating NULL). +*/ + argv = malloc((argc + 10) * sizeof(*argv)); if (!argv) return 1; argv[i++] = LXCINITDIR "/lxc-init"; + argv[i++] = "--name"; + argv[i++] = handler->name; + if (my_args->log_file) { + argv[i++] = "--logfile"; + argv[i++] = my_args->log_file; + } + if (my_args->log_priority) { + argv[i++] = "--logpriority"; + argv[i++] = my_args->log_priority; + } if (my_args->quiet) argv[i++] = "--quiet"; argv[i++] = "--"; @@ -76,11 +91,14 @@ static struct lxc_operations execute_start_ops = { }; int lxc_execute(const char *name, char *const argv[], int quiet, + char *log_file, char *log_priority, struct lxc_conf *conf) { struct execute_args args = { .argv = argv, - .quiet = quiet + .quiet = quiet, + .log_file = log_file, + .log_priority = log_priority }; if (lxc_check_inherited(-1)) diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h index ae8a3f7..96cd735 100644 --- a/src/lxc/lxc.h +++ b/src/lxc/lxc.h @@ -66,6 +66,7 @@ extern int lxc_stop(const char *name); * Returns 0 on sucess, < 0 otherwise */ extern int lxc_execute(const char *name, char *const argv[], int quiet, + char *log_file, char *log_priority, struct lxc_conf *conf); /* diff --git a/src/lxc/lxc_execute.c b/src/lxc/lxc_execute.c index 1eb25a7..82a9235 100644 --- a/src/lxc/lxc_execute.c +++ b/src/lxc/lxc_execute.c @@ -136,5 +136,6 @@ int main(int argc, char *argv[]) if (lxc_config_define_load(&defines, conf)) return -1; - return lxc_execute(my_args.name, my_args.argv, my_args.quiet, conf); + return lxc_execute(my_args.name, my_args.argv, my_args.quiet, + my_args.log_file, my_args.log_priority, conf); } diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c index 17704cd..2f209d1 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -31,9 +31,8 @@ #include #include #include -#define _GNU_SOURCE -#include +#include "arguments.h" #include "log.h" #include "caps.h" #include "error.h" @@ -42,11 +41,31 @@ lxc_log_define(lxc_init, lxc); -static int quiet; +static int my_checker(const struct lxc_arguments* args) +{ + if (!args->argc) { + lxc_error(args, "missing command to execute !"); + return -1; + } + + return 0; +} + +static const struct option my_longopts[] = { + LXC_COMMON_OPTIONS +}; -static struct option options[] = { - { "quiet", no_argument, &quiet, 1 }, - { 0, 0, 0, 0 }, +static struct lxc_arguments my_args = { + .progname = "lxc-init", + .help = "\ +--name=NAME -- COMMAND\n\ +\n\ +lxc-init execs COMMAND into this container acts as a minimal init process\n\ +\n\ +Options :\n\ + -n, --name=NAME NAME for name of the container\n", + .options = my_longopts, + .checker = my_checker, }; static pid_t child_pid; @@ -119,6 +138,8 @@ static int handle_signal(int fd, void* data, struct lxc_epoll_descr *descr) break; default: + NOTICE("forwarding signal %d to child <%d>", siginfo.ssi_signo, + child_pid); kill(child_pid, siginfo.ssi_signo); break; } @@ -128,37 +149,20 @@ static int handle_signal(int fd, void* data, struct lxc_epoll_descr *descr) int main(int argc, char *argv[]) { - int nbargs = 0; int err = -1; - char **aargv; sigset_t mask; struct lxc_epoll_descr mainloop_descr; int signal_fd; - while (1) { - int ret = getopt_long_only
[lxc-devel] [lxc-dev]how to use lxc directly in kernel
Hi I am a newbie to Linux container. Recently,I decide to using lxc derectly on linux kernel,but find it hard to install. (so far as I know,lxc tools is based on GUI Linux distribution). Anyone has this experience? or give me a hint on how to use the lxc directly on linux kernel without the lxc tools? Thanks in advance! --- Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) is intended only for the use of the intended recipient and may be confidential and/or privileged of Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is not the intended recipient, unauthorized use, forwarding, printing, storing, disclosure or copying is strictly prohibited, and may be unlawful.If you have received this communication in error,please immediately notify the sender by return e-mail, and delete the original message and all copies from your system. Thank you. --- -- The demand for IT networking professionals continues to grow, and the demand for specialized networking skills is growing even more rapidly. Take a complimentary Learning@Cisco Self-Assessment and learn about Cisco certifications, training, and career opportunities. http://p.sf.net/sfu/cisco-dev2dev ___ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel