Merge pull request #2464 from poettering/reload-or-try-restart

Fix for #688
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2016-01-28 19:11:30 -05:00
commit 2bc968b748
11 changed files with 39 additions and 19 deletions

View file

@ -733,9 +733,9 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
<listitem>
<para>Restart one or more units specified on the command
line if the units are running. This does nothing if units are not
running. Note that, for compatibility with Red Hat init
scripts, <command>condrestart</command> is equivalent to this
command.</para>
running.</para>
<!-- Note that we don't document condrestart here, as that is just compatibility support, and we generally
don't document that. -->
</listitem>
</varlistentry>
<varlistentry>
@ -748,14 +748,14 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
</listitem>
</varlistentry>
<varlistentry>
<term><command>reload-or-try-restart <replaceable>PATTERN</replaceable>...</command></term>
<term><command>try-reload-or-restart <replaceable>PATTERN</replaceable>...</command></term>
<listitem>
<para>Reload one or more units if they support it. If not,
restart them instead. This does nothing if the units are not
running. Note that, for compatibility with SysV init scripts,
<command>force-reload</command> is equivalent to this
command.</para>
running.</para>
<!-- Note that we don't document force-reload here, as that is just compatibility support, and we generally
don't document that. -->
</listitem>
</varlistentry>
<varlistentry>

View file

@ -170,7 +170,7 @@ _systemctl () {
[STARTABLE_UNITS]='start'
[STOPPABLE_UNITS]='stop condstop kill try-restart condrestart'
[ISOLATABLE_UNITS]='isolate'
[RELOADABLE_UNITS]='reload condreload reload-or-try-restart force-reload'
[RELOADABLE_UNITS]='reload condreload try-reload-or-restart force-reload'
[RESTARTABLE_UNITS]='restart reload-or-restart'
[TARGET_AND_UNITS]='add-wants add-requires'
[MASKED_UNITS]='unmask'

View file

@ -17,7 +17,7 @@
"force-reload:Reload one or more units if possible, otherwise restart if active"
"hibernate:Hibernate the system"
"hybrid-sleep:Hibernate and suspend the system"
"reload-or-try-restart:Reload one or more units if possible, otherwise restart if active"
"try-reload-or-restart:Reload one or more units if possible, otherwise restart if active"
"isolate:Start one unit and stop all others"
"kill:Send signal to processes of a unit"
"is-active:Check whether units are active"
@ -69,7 +69,7 @@
# Deal with any aliases
case $cmd in
condrestart) cmd="try-restart";;
force-reload) cmd="reload-or-try-restart";;
force-reload) cmd="try-reload-or-restart";;
esac
if (( $#cmd )); then
@ -230,7 +230,7 @@ done
}
# Completion functions for RELOADABLE_UNITS
for fun in reload reload-or-try-restart force-reload ; do
for fun in reload try-reload-or-restart force-reload ; do
(( $+functions[_systemctl_$fun] )) || _systemctl_$fun()
{
local _sys_active_units; _systemctl_active_units

View file

@ -987,7 +987,7 @@ int bus_unit_queue_job(
if (type == JOB_RESTART)
type = JOB_RELOAD_OR_START;
else if (type == JOB_TRY_RESTART)
type = JOB_RELOAD;
type = JOB_TRY_RELOAD;
}
r = mac_selinux_unit_access_check(

View file

@ -405,6 +405,13 @@ JobType job_type_collapse(JobType t, Unit *u) {
return JOB_RESTART;
case JOB_TRY_RELOAD:
s = unit_active_state(u);
if (UNIT_IS_INACTIVE_OR_DEACTIVATING(s))
return JOB_NOP;
return JOB_RELOAD;
case JOB_RELOAD_OR_START:
s = unit_active_state(u);
if (UNIT_IS_INACTIVE_OR_DEACTIVATING(s))
@ -1202,6 +1209,7 @@ static const char* const job_type_table[_JOB_TYPE_MAX] = {
[JOB_RELOAD_OR_START] = "reload-or-start",
[JOB_RESTART] = "restart",
[JOB_TRY_RESTART] = "try-restart",
[JOB_TRY_RELOAD] = "try-reload",
[JOB_NOP] = "nop",
};

View file

@ -66,6 +66,9 @@ enum JobType {
* Thus we never need to merge it with anything. */
JOB_TRY_RESTART = _JOB_TYPE_MAX_IN_TRANSACTION, /* if running, stop and then start */
/* Similar to JOB_TRY_RESTART but collapses to JOB_RELOAD or JOB_NOP */
JOB_TRY_RELOAD,
/* JOB_RELOAD_OR_START won't enter into a transaction and cannot result
* from transaction merging (there's no way for JOB_RELOAD and
* JOB_START to meet in one transaction). It can result from a merge

View file

@ -3097,18 +3097,18 @@ ManagerState manager_state(Manager *m) {
/* Is the special shutdown target queued? If so, we are in shutdown state */
u = manager_get_unit(m, SPECIAL_SHUTDOWN_TARGET);
if (u && u->job && IN_SET(u->job->type, JOB_START, JOB_RESTART, JOB_TRY_RESTART, JOB_RELOAD_OR_START))
if (u && u->job && IN_SET(u->job->type, JOB_START, JOB_RESTART, JOB_RELOAD_OR_START))
return MANAGER_STOPPING;
/* Are the rescue or emergency targets active or queued? If so we are in maintenance state */
u = manager_get_unit(m, SPECIAL_RESCUE_TARGET);
if (u && (UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u)) ||
(u->job && IN_SET(u->job->type, JOB_START, JOB_RESTART, JOB_TRY_RESTART, JOB_RELOAD_OR_START))))
(u->job && IN_SET(u->job->type, JOB_START, JOB_RESTART, JOB_RELOAD_OR_START))))
return MANAGER_MAINTENANCE;
u = manager_get_unit(m, SPECIAL_EMERGENCY_TARGET);
if (u && (UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u)) ||
(u->job && IN_SET(u->job->type, JOB_START, JOB_RESTART, JOB_TRY_RESTART, JOB_RELOAD_OR_START))))
(u->job && IN_SET(u->job->type, JOB_START, JOB_RESTART, JOB_RELOAD_OR_START))))
return MANAGER_MAINTENANCE;
/* Are there any failed units? If so, we are in degraded mode */

View file

@ -1010,7 +1010,13 @@ int transaction_add_job_and_dependencies(
if (type == JOB_RELOAD) {
SET_FOREACH(dep, ret->unit->dependencies[UNIT_PROPAGATES_RELOAD_TO], i) {
r = transaction_add_job_and_dependencies(tr, JOB_RELOAD, dep, ret, false, false, false, ignore_order, e);
JobType nt;
nt = job_type_collapse(JOB_TRY_RELOAD, dep);
if (nt == JOB_NOP)
continue;
r = transaction_add_job_and_dependencies(tr, nt, dep, ret, false, false, false, ignore_order, e);
if (r < 0) {
log_unit_warning(dep,
"Cannot add dependency reload job, ignoring: %s",

View file

@ -1894,6 +1894,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
case JOB_RELOAD:
case JOB_RELOAD_OR_START:
case JOB_TRY_RELOAD:
if (u->job->state == JOB_RUNNING) {
if (ns == UNIT_ACTIVE)
@ -2107,6 +2108,7 @@ bool unit_job_is_applicable(Unit *u, JobType j) {
return unit_can_start(u);
case JOB_RELOAD:
case JOB_TRY_RELOAD:
return unit_can_reload(u);
case JOB_RELOAD_OR_START:

View file

@ -2100,7 +2100,7 @@ static int check_wait_response(BusWaitForJobs *d, bool quiet, const char *extra_
else if (streq(d->result, "dependency"))
log_error("A dependency job for %s failed. See 'journalctl -xe' for details.", strna(d->name));
else if (streq(d->result, "invalid"))
log_error("Job for %s invalid.", strna(d->name));
log_error("%s is not active, cannot reload.", strna(d->name));
else if (streq(d->result, "assert"))
log_error("Assertion failed on job for %s.", strna(d->name));
else if (streq(d->result, "unsupported"))

View file

@ -2538,6 +2538,7 @@ static const struct {
{ "try-restart", "TryRestartUnit" },
{ "condrestart", "TryRestartUnit" },
{ "reload-or-restart", "ReloadOrRestartUnit" },
{ "try-reload-or-restart", "ReloadOrTryRestartUnit" },
{ "reload-or-try-restart", "ReloadOrTryRestartUnit" },
{ "condreload", "ReloadOrTryRestartUnit" },
{ "force-reload", "ReloadOrTryRestartUnit" }
@ -6234,8 +6235,8 @@ static void systemctl_help(void) {
" try-restart NAME... Restart one or more units if active\n"
" reload-or-restart NAME... Reload one or more units if possible,\n"
" otherwise start or restart\n"
" reload-or-try-restart NAME... Reload one or more units if possible,\n"
" otherwise restart if active\n"
" try-reload-or-restart NAME... If active, reload one or more units,\n"
" if supported, otherwise restart\n"
" isolate NAME Start one unit and stop all others\n"
" kill NAME... Send signal to processes of a unit\n"
" is-active PATTERN... Check whether units are active\n"