From: Stéphane Graber Date: Fri, 7 Mar 2014 18:32:16 +0000 (-0500) Subject: lxc-autostart: Add a new --ignore-auto/-A flag X-Git-Tag: lxc-1.1.0.alpha1~229 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e582991fd00734436ad0cc95c42cc3d16fd3d229;p=thirdparty%2Flxc.git lxc-autostart: Add a new --ignore-auto/-A flag 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 Acked-by: Serge E. Hallyn --- diff --git a/config/init/sysvinit/lxc b/config/init/sysvinit/lxc index 91281877a..436eef488 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 1a5c5c996..d5131adc4 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 985cbe436..3d423dde4 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 -r -s -a + -A -g groups -t timeout @@ -169,6 +170,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + + + + + + + Ignore the lxc.start.auto flag. Combined with + -a, will select all containers on the system. + + + diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h index 767bfcfc7..e5f06705a 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 cfb24d068..ec9d9ba83 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; }