summaryrefslogtreecommitdiff
path: root/src/machine
diff options
context:
space:
mode:
Diffstat (limited to 'src/machine')
-rw-r--r--src/machine/machinectl.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index a147fae0bd..80eebf36d3 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -77,6 +77,7 @@ static bool arg_quiet = false;
static bool arg_ask_password = true;
static unsigned arg_lines = 10;
static OutputMode arg_output = OUTPUT_SHORT;
+static bool arg_now = false;
static bool arg_force = false;
static ImportVerify arg_verify = IMPORT_VERIFY_SIGNATURE;
static const char* arg_format = NULL;
@@ -1673,7 +1674,26 @@ static int enable_machine(int argc, char *argv[], void *userdata) {
goto finish;
}
- r = 0;
+ if (arg_now) {
+ _cleanup_strv_free_ char **new_args = NULL;
+
+ new_args = strv_new(streq(argv[0], "enable") ? "start" : "poweroff");
+ if (!new_args) {
+ r = log_oom();
+ goto finish;
+ }
+
+ r = strv_extend_strv(&new_args, argv + 1, /* filter_duplicates = */ false);
+ if (r < 0) {
+ log_oom();
+ goto finish;
+ }
+
+ if (streq(argv[0], "enable"))
+ r = start_machine(strv_length(new_args), new_args, userdata);
+ else
+ r = poweroff_machine(strv_length(new_args), new_args, userdata);
+ }
finish:
install_changes_free(changes, n_changes);
@@ -2471,8 +2491,10 @@ static int help(int argc, char *argv[], void *userdata) {
" json, json-pretty, json-sse, json-seq, cat,\n"
" verbose, export, with-unit)\n"
" --verify=MODE Verification mode for downloaded images (no,\n"
- " checksum, signature)\n"
+ " checksum, signature)\n"
" --force Download image even if already exists\n"
+ " --now Start or power off container after enabling or\n"
+ " disabling it\n"
"\nSee the %s for details.\n",
program_invocation_short_name,
ansi_highlight(),
@@ -2496,6 +2518,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_MKDIR,
ARG_NO_ASK_PASSWORD,
ARG_VERIFY,
+ ARG_NOW,
ARG_FORCE,
ARG_FORMAT,
ARG_UID,
@@ -2522,6 +2545,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "output", required_argument, NULL, 'o' },
{ "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
{ "verify", required_argument, NULL, ARG_VERIFY },
+ { "now", no_argument, NULL, ARG_NOW },
{ "force", no_argument, NULL, ARG_FORCE },
{ "format", required_argument, NULL, ARG_FORMAT },
{ "uid", required_argument, NULL, ARG_UID },
@@ -2698,6 +2722,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_verify = r;
break;
+ case ARG_NOW:
+ arg_now = true;
+ break;
+
case ARG_FORCE:
arg_force = true;
break;