[lxc-devel] [PATCH 2/2] lxc-autostart: Add a new --ignore-auto/-A flag

Stéphane Graber stgraber at ubuntu.com
Fri Mar 7 19:24:40 UTC 2014


When passed, this flag will cause lxc-autostart to ignore the value of
lxc.start.auto.

This then allows things like: lxc-autostart -s -a -A

Which will select all containers regardless of groups (-a), regardless
of whether they are actually marked as auto-started (-A) and will shut
them down (-s).

Update our init scripts to use the new feature.

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 config/init/sysvinit/lxc     |  2 +-
 config/init/upstart/lxc.conf |  4 ++++
 doc/lxc-autostart.sgml.in    | 13 +++++++++++++
 src/lxc/arguments.h          |  1 +
 src/lxc/lxc_autostart.c      |  6 +++++-
 5 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/config/init/sysvinit/lxc b/config/init/sysvinit/lxc
index 9128187..436eef4 100755
--- a/config/init/sysvinit/lxc
+++ b/config/init/sysvinit/lxc
@@ -50,7 +50,7 @@ case "$1" in
 	touch /var/lock/subsys/lxc
 	;;
   stop)
-	action $"Stopping LXC containers: " /usr/bin/lxc-autostart -s
+	action $"Stopping LXC containers: " /usr/bin/lxc-autostart -a -A -s
 	rm -f /var/lock/subsys/lxc
 	;;
   restart|reload|force-reload)
diff --git a/config/init/upstart/lxc.conf b/config/init/upstart/lxc.conf
index 1a5c5c9..d5131ad 100644
--- a/config/init/upstart/lxc.conf
+++ b/config/init/upstart/lxc.conf
@@ -25,3 +25,7 @@ pre-start script
 		(start lxc-instance NAME=$1 && sleep $2) || true
 	done
 end script
+
+post-stop script
+	lxc-autostart -a -A -s || true
+end script
diff --git a/doc/lxc-autostart.sgml.in b/doc/lxc-autostart.sgml.in
index 985cbe4..3d423dd 100644
--- a/doc/lxc-autostart.sgml.in
+++ b/doc/lxc-autostart.sgml.in
@@ -51,6 +51,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
             <arg choice="opt">-r</arg>
             <arg choice="opt">-s</arg>
             <arg choice="opt">-a</arg>
+            <arg choice="opt">-A</arg>
             <arg choice="opt">-g <replaceable>groups</replaceable></arg>
             <arg choice="opt">-t <replaceable>timeout</replaceable></arg>
         </cmdsynopsis>
@@ -169,6 +170,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
                     </para>
                 </listitem>
             </varlistentry>
+
+            <varlistentry>
+                <term>
+                    <option>-A,--ignore-auto</option>
+                </term>
+                <listitem>
+                    <para>
+                        Ignore the lxc.start.auto flag. Combined with
+                        -a, will select all containers on the system.
+                    </para>
+                </listitem>
+            </varlistentry>
         </variablelist>
     </refsect1>
 
diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h
index 767bfcf..e5f0670 100644
--- a/src/lxc/arguments.h
+++ b/src/lxc/arguments.h
@@ -90,6 +90,7 @@ struct lxc_arguments {
 
 	/* auto-start */
 	int all;
+	int ignore_auto;
 	int list;
 	char *groups;
 
diff --git a/src/lxc/lxc_autostart.c b/src/lxc/lxc_autostart.c
index cfb24d0..ec9d9ba 100644
--- a/src/lxc/lxc_autostart.c
+++ b/src/lxc/lxc_autostart.c
@@ -37,6 +37,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
 	case 'r': args->reboot = 1; break;
 	case 's': args->shutdown = 1; break;
 	case 'a': args->all = 1; break;
+	case 'A': args->ignore_auto = 1; break;
 	case 'g': args->groups = arg; break;
 	case 't': args->timeout = atoi(arg); break;
 	}
@@ -49,6 +50,7 @@ static const struct option my_longopts[] = {
 	{"reboot", no_argument, 0, 'r'},
 	{"shutdown", no_argument, 0, 's'},
 	{"all", no_argument, 0, 'a'},
+	{"ignore-auto", no_argument, 0, 'A'},
 	{"groups", required_argument, 0, 'g'},
 	{"timeout", required_argument, 0, 't'},
 	{"help", no_argument, 0, 'h'},
@@ -68,6 +70,7 @@ Options:\n\
   -s, --shutdown    shutdown the containers instead of starting them\n\
 \n\
   -a, --all         list all auto-started containers (ignore groups)\n\
+  -A, --ignore-auto ignore lxc.start.auto and select all matching containers\n\
   -g, --groups      list of groups (comma separated) to select\n\
   -t, --timeout=T   wait T seconds before hard-stopping\n",
 	.options  = my_longopts,
@@ -246,7 +249,8 @@ int main(int argc, char *argv[])
 			continue;
 		}
 
-		if (get_config_integer(c, "lxc.start.auto") != 1) {
+		if (!my_args.ignore_auto &&
+		    get_config_integer(c, "lxc.start.auto") != 1) {
 			lxc_container_put(c);
 			continue;
 		}
-- 
1.9.0



More information about the lxc-devel mailing list