Skip to content

Commit

Permalink
Add lxc-autostart
Browse files Browse the repository at this point in the history
This introduces a new lxc-autostart binary (and associated manpage)
which will let you start/shutdown/kill/restart any container that's
marked as lxc.start.auto=1. It respects the lxc.start.delay value,
sorts by lxc.start.order and filters by lxc.group.

By default it'll affect all containers that DO NOT have lxc.group
set. If -g is specified, ONLY containers in those group will be
affected. To have a command applied to all containers, the -a
argument can be used.

A -L flag is also offered for distributions wishing to start the
containers themselves while still using LXC's calculated order and
wait delays. Instead of performing the action, it'll print the container
name and (if relevant for the action) the wait time.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
  • Loading branch information
stgraber committed Dec 19, 2013
1 parent cfd149a commit a6adab2
Show file tree
Hide file tree
Showing 8 changed files with 519 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -43,6 +43,7 @@ templates/lxc-ubuntu-cloud


src/lxc/lxc-attach
src/lxc/lxc-autostart
src/lxc/lxc-cgroup
src/lxc/lxc-checkconfig
src/lxc/lxc-checkpoint
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -474,6 +474,7 @@ AC_CONFIG_FILES([
doc/api/Makefile
doc/legacy/lxc-ls.sgml
doc/lxc-attach.sgml
doc/lxc-autostart.sgml
doc/lxc-cgroup.sgml
doc/lxc-checkconfig.sgml
doc/lxc-checkpoint.sgml
Expand Down
1 change: 1 addition & 0 deletions doc/Makefile.am
Expand Up @@ -15,6 +15,7 @@ EXTRA_DIST = \
if ENABLE_DOCBOOK
man_MANS = \
lxc-attach.1 \
lxc-autostart.1 \
lxc-cgroup.1 \
lxc-checkconfig.1 \
lxc-checkpoint.1 \
Expand Down
173 changes: 173 additions & 0 deletions doc/lxc-autostart.sgml.in
@@ -0,0 +1,173 @@
<!--

lxc-autostart

(C) Copyright 2013 Canonical Ltd.

Authors:
Stéphane Graber <stgraber@ubuntu.com>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

-->

<!DOCTYPE refentry PUBLIC @docdtd@ [
<!ENTITY commonoptions SYSTEM "@builddir@/common_options.sgml">
<!ENTITY seealso SYSTEM "@builddir@/see_also.sgml">
]>

<refentry>
<docinfo><date>@LXC_GENERATE_DATE@</date></docinfo>
<refmeta>
<refentrytitle>lxc-autostart</refentrytitle>
<manvolnum>1</manvolnum>
</refmeta>

<refnamediv>
<refname>lxc-autostart</refname>

<refpurpose>
start/stop/kill auto-started containers
</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>lxc-autostart</command>
<arg choice="opt">-k</arg>
<arg choice="opt">-L</arg>
<arg choice="opt">-r</arg>
<arg choice="opt">-s</arg>
<arg choice="opt">-a</arg>
<arg choice="opt">-g <replaceable>groups</replaceable></arg>
<arg choice="opt">-t <replaceable>timeout</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>

<refsect1>
<title>Description</title>

<para>
<command>lxc-autostart</command> processes containers
with lxc.start.auto set. It lets the user start, shutdown,
kill, restart containers in the right order, waiting the
right time. Supports filtering by lxc.group or just run
against all defined containers. It can also be used by
external tools in list mode where no action will be performed
and the list of affected containers (and if relevant, delays)
will be shown.
</para>

<para>
The <optional>-r</optional>, <optional>-s</optional>
and <optional>-k</optional> options specify the action to perform.
If none is specified, then the containers will be started.
<optional>-a</optional> and <optional>-g</optional> are used to
specify which containers will be affected. By default only
containers without a lxc.group set will be affected.
<optional>-t TIMEOUT</optional> specifies the maximum amount
of time to wait for the container to complete the shutdown
or reboot.
</para>
</refsect1>

<refsect1>
<title>Options</title>
<variablelist>
<varlistentry>
<term>
<option>-r,--reboot </option>
</term>
<listitem>
<para>
Request a reboot of the container.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>
<option>-s,--shutdown </option>
</term>
<listitem>
<para>
Only request a clean shutdown, do not kill the
container tasks if the clean shutdown fails.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>
<option>-k,--kill </option>
</term>
<listitem>
<para>
Rather than requesting a clean shutdown of the
container, explicitly kill all tasks in the container.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>
<option>-L,--list </option>
</term>
<listitem>
<para>
Rather than performing the action, just print
the container name.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>
<option>-t,--timeout <replaceable>TIMEOUT</replaceable></option>
</term>
<listitem>
<para>
Wait TIMEOUT seconds before hard-stopping the
container of (in the reboot case) returning failure.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

&seealso;

<refsect1>
<title>Author</title>
<para>Stéphane Graber <email>stgraber@ubuntu.com</email></para>
</refsect1>
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:2
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:nil
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
2 changes: 2 additions & 0 deletions src/lxc/Makefile.am
Expand Up @@ -170,6 +170,7 @@ endif

bin_PROGRAMS = \
lxc-attach \
lxc-autostart \
lxc-unshare \
lxc-stop \
lxc-start \
Expand Down Expand Up @@ -203,6 +204,7 @@ endif
LDADD=liblxc.so @CAP_LIBS@ @APPARMOR_LIBS@ @SECCOMP_LIBS@

lxc_attach_SOURCES = lxc_attach.c
lxc_autostart_SOURCES = lxc_autostart.c
lxc_cgroup_SOURCES = lxc_cgroup.c
lxc_checkpoint_SOURCES = lxc_checkpoint.c
lxc_config_SOURCES = lxc_config.c
Expand Down
2 changes: 1 addition & 1 deletion src/lxc/arguments.c
Expand Up @@ -229,7 +229,7 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,

/* Check the command options */

if (!args->name) {
if (!args->name && strcmp(args->progname, "lxc-autostart") != 0) {
lxc_error(args, "missing container name, use --name option");
return -1;
}
Expand Down
5 changes: 5 additions & 0 deletions src/lxc/arguments.h
Expand Up @@ -89,6 +89,11 @@ struct lxc_arguments {
char *lvname, *vgname, *thinpool;
char *zfsroot, *lowerdir, *dir;

/* auto-start */
int all;
int list;
char *groups;

/* remaining arguments */
char *const *argv;
int argc;
Expand Down

0 comments on commit a6adab2

Please sign in to comment.