Commit e582991f by Stéphane Graber

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: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent e447a8a7
...@@ -50,7 +50,7 @@ case "$1" in ...@@ -50,7 +50,7 @@ case "$1" in
touch /var/lock/subsys/lxc touch /var/lock/subsys/lxc
;; ;;
stop) 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 rm -f /var/lock/subsys/lxc
;; ;;
restart|reload|force-reload) restart|reload|force-reload)
......
...@@ -25,3 +25,7 @@ pre-start script ...@@ -25,3 +25,7 @@ pre-start script
(start lxc-instance NAME=$1 && sleep $2) || true (start lxc-instance NAME=$1 && sleep $2) || true
done done
end script end script
post-stop script
lxc-autostart -a -A -s || true
end script
...@@ -51,6 +51,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ...@@ -51,6 +51,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
<arg choice="opt">-r</arg> <arg choice="opt">-r</arg>
<arg choice="opt">-s</arg> <arg choice="opt">-s</arg>
<arg choice="opt">-a</arg> <arg choice="opt">-a</arg>
<arg choice="opt">-A</arg>
<arg choice="opt">-g <replaceable>groups</replaceable></arg> <arg choice="opt">-g <replaceable>groups</replaceable></arg>
<arg choice="opt">-t <replaceable>timeout</replaceable></arg> <arg choice="opt">-t <replaceable>timeout</replaceable></arg>
</cmdsynopsis> </cmdsynopsis>
...@@ -169,6 +170,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ...@@ -169,6 +170,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
</para> </para>
</listitem> </listitem>
</varlistentry> </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> </variablelist>
</refsect1> </refsect1>
......
...@@ -90,6 +90,7 @@ struct lxc_arguments { ...@@ -90,6 +90,7 @@ struct lxc_arguments {
/* auto-start */ /* auto-start */
int all; int all;
int ignore_auto;
int list; int list;
char *groups; char *groups;
......
...@@ -37,6 +37,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg) ...@@ -37,6 +37,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
case 'r': args->reboot = 1; break; case 'r': args->reboot = 1; break;
case 's': args->shutdown = 1; break; case 's': args->shutdown = 1; break;
case 'a': args->all = 1; break; case 'a': args->all = 1; break;
case 'A': args->ignore_auto = 1; break;
case 'g': args->groups = arg; break; case 'g': args->groups = arg; break;
case 't': args->timeout = atoi(arg); break; case 't': args->timeout = atoi(arg); break;
} }
...@@ -49,6 +50,7 @@ static const struct option my_longopts[] = { ...@@ -49,6 +50,7 @@ static const struct option my_longopts[] = {
{"reboot", no_argument, 0, 'r'}, {"reboot", no_argument, 0, 'r'},
{"shutdown", no_argument, 0, 's'}, {"shutdown", no_argument, 0, 's'},
{"all", no_argument, 0, 'a'}, {"all", no_argument, 0, 'a'},
{"ignore-auto", no_argument, 0, 'A'},
{"groups", required_argument, 0, 'g'}, {"groups", required_argument, 0, 'g'},
{"timeout", required_argument, 0, 't'}, {"timeout", required_argument, 0, 't'},
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
...@@ -68,6 +70,7 @@ Options:\n\ ...@@ -68,6 +70,7 @@ Options:\n\
-s, --shutdown shutdown the containers instead of starting them\n\ -s, --shutdown shutdown the containers instead of starting them\n\
\n\ \n\
-a, --all list all auto-started containers (ignore groups)\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\ -g, --groups list of groups (comma separated) to select\n\
-t, --timeout=T wait T seconds before hard-stopping\n", -t, --timeout=T wait T seconds before hard-stopping\n",
.options = my_longopts, .options = my_longopts,
...@@ -246,7 +249,8 @@ int main(int argc, char *argv[]) ...@@ -246,7 +249,8 @@ int main(int argc, char *argv[])
continue; 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); lxc_container_put(c);
continue; continue;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment