systemctl: introduce enqueue-marked-jobs verb, stop lumping it with distinct verbs

This commit is contained in:
Mike Yuan
2026-02-24 15:41:20 +01:00
parent a8ceed0000
commit c008f88ded
4 changed files with 36 additions and 11 deletions

View File

@@ -499,6 +499,20 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
do not document that. -->
</listitem>
</varlistentry>
<varlistentry>
<term><command>enqueue-marked-jobs</command></term>
<listitem><para>Enqueue start/stop/restart/reload jobs for all units that have the respective
<literal>needs-*</literal> markers set. When a unit marked for reload does not support reload,
restart will be queued. Those properties can be set using <command>set-property Markers=…</command>.</para>
<para>Unless <option>--no-block</option> is used, <command>systemctl</command> will wait for the
queued jobs to finish.</para>
<xi:include href="version-info.xml" xpointer="v260"/></listitem>
</varlistentry>
<varlistentry>
<term><command>reload-or-restart <replaceable>PATTERN</replaceable></command></term>

View File

@@ -65,6 +65,7 @@ static int systemctl_main(int argc, char *argv[]) {
{ "reload", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start },
{ "restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start },
{ "try-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start },
{ "enqueue-marked-jobs", 1, 1, VERB_ONLINE_ONLY, verb_start },
{ "reload-or-restart", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_start },
{ "reload-or-try-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, /* For compatibility with old systemctl <= 228 */
{ "try-reload-or-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start },

View File

@@ -295,6 +295,7 @@ int verb_start(int argc, char *argv[], void *userdata) {
const char *method, *job_type, *mode, *one_name, *suffix = NULL;
_cleanup_free_ char **stopped_units = NULL; /* Do not use _cleanup_strv_free_ */
_cleanup_strv_free_ char **names = NULL;
bool is_enqueue_marked_jobs = false;
int r, ret = EXIT_SUCCESS;
sd_bus *bus;
@@ -331,13 +332,27 @@ int verb_start(int argc, char *argv[], void *userdata) {
job_type = "start";
mode = "isolate";
suffix = ".target";
} else if (!arg_marked) {
} else if (streq(argv[0], "enqueue-marked-jobs") || arg_marked) {
is_enqueue_marked_jobs = true;
method = job_type = mode = NULL;
if (arg_wait)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--wait is not supported for enqueue-marked-jobs.");
if (arg_show_transaction)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--show-transaction is not supported for enqueue-marked-jobs.");
if (arg_marked)
log_warning("--marked is deprecated. Please use systemctl enqueue-marked-jobs instead.");
} else {
/* A command in style of "systemctl start <unit1> <unit2> …", "systemctl stop <unit1> <unit2> …" and so on */
method = verb_to_method(argv[0]);
job_type = verb_to_job_type(argv[0]);
mode = arg_job_mode();
} else
method = job_type = mode = NULL;
}
one_name = NULL;
}
@@ -357,7 +372,7 @@ int verb_start(int argc, char *argv[], void *userdata) {
names = strv_new(one_name);
if (!names)
return log_oom();
} else if (!arg_marked) {
} else if (!is_enqueue_marked_jobs) {
bool expanded;
r = expand_unit_names(bus, strv_skip(argv, 1), suffix, &names, &expanded);
@@ -387,7 +402,7 @@ int verb_start(int argc, char *argv[], void *userdata) {
}
_cleanup_(fork_notify_terminate) PidRef journal_pid = PIDREF_NULL;
if (arg_marked)
if (is_enqueue_marked_jobs)
ret = enqueue_marked_jobs(bus, w);
else {
if (arg_verbose)

View File

@@ -143,6 +143,7 @@ static int systemctl_help(void) {
" reload UNIT... Reload one or more units\n"
" restart UNIT... Start or restart one or more units\n"
" try-restart UNIT... Restart one or more units if active\n"
" enqueue-marked-jobs Enqueue all marked unit jobs\n"
" reload-or-restart UNIT... Reload one or more units if possible,\n"
" otherwise start or restart\n"
" try-reload-or-restart UNIT... If active, reload one or more units,\n"
@@ -1077,12 +1078,6 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
if (optind + 1 < argc)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"No additional arguments allowed with 'reload-or-restart --marked'.");
if (arg_wait)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--marked --wait is not supported.");
if (arg_show_transaction)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--marked --show-transaction is not supported.");
} else if (do_reload_or_restart) {
if (optind + 1 >= argc)