diff options
-rw-r--r-- | man/systemctl.xml | 34 | ||||
-rw-r--r-- | src/dbus-manager.c | 26 | ||||
-rw-r--r-- | src/dbus-unit.c | 16 | ||||
-rw-r--r-- | src/dbus-unit.h | 10 | ||||
-rw-r--r-- | src/systemctl.c | 35 |
5 files changed, 100 insertions, 21 deletions
diff --git a/man/systemctl.xml b/man/systemctl.xml index 22d3f6ee5e..d73e974e3e 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -194,13 +194,6 @@ 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> <listitem><para>Asks all services @@ -227,6 +220,33 @@ </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> <listitem><para>Start the unit diff --git a/src/dbus-manager.c b/src/dbus-manager.c index f52b06e5fb..c717ccd81f 100644 --- a/src/dbus-manager.c +++ b/src/dbus-manager.c @@ -62,6 +62,16 @@ " <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" \ @@ -239,6 +249,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *reply = NULL; char * path = NULL; JobType job_type = _JOB_TYPE_INVALID; + bool reload_if_possible = false; assert(connection); assert(message); @@ -310,7 +321,13 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, 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; @@ -739,6 +756,13 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, 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); diff --git a/src/dbus-unit.c b/src/dbus-unit.c index 735e5a53f2..da7d1bd5b7 100644 --- a/src/dbus-unit.c +++ b/src/dbus-unit.c @@ -260,6 +260,7 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn DBusError error; JobType job_type = _JOB_TYPE_INVALID; char *path = NULL; + bool reload_if_possible = false; dbus_error_init(&error); @@ -273,7 +274,13 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn 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; @@ -296,6 +303,13 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn 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); diff --git a/src/dbus-unit.h b/src/dbus-unit.h index 17965b618e..1d11af3a04 100644 --- a/src/dbus-unit.h +++ b/src/dbus-unit.h @@ -36,6 +36,10 @@ " <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" \ @@ -44,7 +48,11 @@ " <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" \ diff --git a/src/systemctl.c b/src/systemctl.c index 4218a22b97..bdb294ede0 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -733,10 +733,13 @@ static int start_unit(DBusConnection *bus, char **args, unsigned 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") || @@ -2497,7 +2500,8 @@ static int systemctl_help(void) { " -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" @@ -2507,12 +2511,18 @@ static int systemctl_help(void) { " 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" @@ -2530,9 +2540,9 @@ static int systemctl_help(void) { " 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; @@ -3193,6 +3203,9 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[]) { { "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 }, |