specified on the command
line.</para></listitem>
</varlistentry>
- <varlistentry>
- <term><command>restart [NAME...]</command></term>
-
- <listitem><para>Restart one or more
- units specified on the command
- line.</para></listitem>
- </varlistentry>
<varlistentry>
<term><command>reload [NAME...]</command></term>
commands.</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><command>restart [NAME...]</command></term>
+
+ <listitem><para>Restart one or more
+ units specified on the command
+ line. If the units are not running yet
+ they will be
+ started.</para></listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><command>try-restart [NAME...]</command></term>
+
+ <listitem><para>Restart one or more
+ units specified on the command
+ line. If the units are not running yet
+ the operation will
+ fail.</para></listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><command>reload-or-restart [NAME...]</command></term>
+ <term><command>reload-or-try-restart [NAME...]</command></term>
+
+ <listitem><para>Reload one or more
+ units if they support it. If not
+ restart them
+ instead.</para></listitem>
+ </varlistentry>
<varlistentry>
<term><command>isolate [NAME]</command></term>
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
+ " <method name=\"ReloadOrRestartUnit\">\n" \
+ " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
+ " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
+ " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ " <method name=\"ReloadOrTryRestartUnit\">\n" \
+ " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
+ " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
+ " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
+ " </method>\n" \
" <method name=\"GetJob\">\n" \
" <arg name=\"id\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
DBusMessage *reply = NULL;
char * path = NULL;
JobType job_type = _JOB_TYPE_INVALID;
+ bool reload_if_possible = false;
assert(connection);
assert(message);
job_type = JOB_RESTART;
else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "TryRestartUnit"))
job_type = JOB_TRY_RESTART;
- else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetJob")) {
+ else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrRestartUnit")) {
+ reload_if_possible = true;
+ job_type = JOB_RESTART;
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrTryRestartUnit")) {
+ reload_if_possible = true;
+ job_type = JOB_TRY_RESTART;
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetJob")) {
uint32_t id;
Job *j;
if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
return bus_send_error_reply(m, connection, message, &error, r);
+ if (reload_if_possible && unit_can_reload(u)) {
+ if (job_type == JOB_RESTART)
+ job_type = JOB_RELOAD_OR_START;
+ else if (job_type == JOB_TRY_RESTART)
+ job_type = JOB_RELOAD;
+ }
+
if (job_type == JOB_START && u->meta.only_by_dependency) {
dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Unit may be activated by dependency only.");
return bus_send_error_reply(m, connection, message, &error, -EPERM);
DBusError error;
JobType job_type = _JOB_TYPE_INVALID;
char *path = NULL;
+ bool reload_if_possible = false;
dbus_error_init(&error);
job_type = JOB_RESTART;
else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "TryRestart"))
job_type = JOB_TRY_RESTART;
- else if (UNIT_VTABLE(u)->bus_message_handler)
+ else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "ReloadOrRestart")) {
+ reload_if_possible = true;
+ job_type = JOB_RESTART;
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "ReloadOrTryRestart")) {
+ reload_if_possible = true;
+ job_type = JOB_TRY_RESTART;
+ } else if (UNIT_VTABLE(u)->bus_message_handler)
return UNIT_VTABLE(u)->bus_message_handler(u, connection, message);
else
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
DBUS_TYPE_INVALID))
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ if (reload_if_possible && unit_can_reload(u)) {
+ if (job_type == JOB_RESTART)
+ job_type = JOB_RELOAD_OR_START;
+ else if (job_type == JOB_TRY_RESTART)
+ job_type = JOB_RELOAD;
+ }
+
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
+ " <method name=\"Reload\">\n" \
+ " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
+ " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
+ " </method>\n" \
" <method name=\"Restart\">\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
- " <method name=\"Reload\">\n" \
+ " <method name=\"ReloadOrRestart\">\n" \
+ " <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
+ " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ " <method name=\"ReloadOrTryRestart\">\n" \
" <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
if (arg_action == ACTION_SYSTEMCTL) {
method =
- streq(args[0], "stop") ? "StopUnit" :
- streq(args[0], "reload") ? "ReloadUnit" :
- streq(args[0], "restart") ? "RestartUnit" :
- "StartUnit";
+ streq(args[0], "stop") ? "StopUnit" :
+ streq(args[0], "reload") ? "ReloadUnit" :
+ streq(args[0], "restart") ? "RestartUnit" :
+ streq(args[0], "try-restart") ? "TryRestartUnit" :
+ streq(args[0], "reload-or-restart") ? "ReloadOrRestartUnit" :
+ streq(args[0], "reload-or-try-restart") ? "ReloadOrTryRestartUnit" :
+ "StartUnit";
mode =
(streq(args[0], "isolate") ||
" -t --type=TYPE List only units of a particular type\n"
" -p --property=NAME Show only properties by this name\n"
" -a --all Show all units/properties, including dead/empty ones\n"
- " --fail When installing a new job, fail if conflicting jobs are pending\n"
+ " --fail When installing a new job, fail if conflicting jobs are\n"
+ " pending\n"
" --system Connect to system bus\n"
" --session Connect to session bus\n"
" -q --quiet Suppress output\n"
" list-units List units\n"
" start [NAME...] Start one or more units\n"
" stop [NAME...] Stop one or more units\n"
- " restart [NAME...] Restart one or more units\n"
" reload [NAME...] Reload one or more units\n"
+ " restart [NAME...] Start or restart one or more units\n"
+ " try-restart [NAME...] Restart one or more units if active\n"
+ " reload-or-restart [NAME...] Reload one or more units is possible,\n"
+ " otherwise start or restart\n"
+ " reload-or-try-restart [NAME...] Reload one or more units is possible,\n"
+ " otherwise restart if active\n"
" isolate [NAME] Start one unit and stop all others\n"
- " check [NAME...] Check whether any of the passed units are active\n"
+ " check [NAME...] Check whether units are active\n"
" status [NAME...] Show status of one or more units\n"
- " show [NAME...|JOB...] Show properties of one or more units/jobs/manager\n"
+ " show [NAME...|JOB...] Show properties of one or more\n"
+ " units/jobs/manager\n"
" load [NAME...] Load one or more units\n"
" list-jobs List jobs\n"
" cancel [JOB...] Cancel one or more jobs\n"
" halt Shut down and halt the system\n"
" poweroff Shut down and power-off the system\n"
" reboot Shut down and reboot the system\n"
- " default Enter default mode\n"
- " rescue Enter rescue mode\n"
- " emergency Enter emergency mode\n",
+ " rescue Enter system rescue mode\n"
+ " emergency Enter system emergency mode\n"
+ " default Enter system default mode\n",
program_invocation_short_name);
return 0;
{ "stop", MORE, 2, start_unit },
{ "reload", MORE, 2, start_unit },
{ "restart", MORE, 2, start_unit },
+ { "try-restart", MORE, 2, start_unit },
+ { "reload-or-restart", MORE, 2, start_unit },
+ { "reload-or-try-restart", MORE, 2, start_unit },
{ "isolate", EQUAL, 2, start_unit },
{ "check", MORE, 2, check_unit },
{ "show", MORE, 1, show },