From abb99360d3317980fc8843f79b67c763cd4a9a2c Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 26 Jan 2022 19:00:25 +0000 Subject: [PATCH 1/2] core: do not restart a service with Restart=always when ExecCondition fails When a Condition*= fails, and a service has Restart=always, the service is not restarted. Follow the same behaviour for ExecCondition= to avoid inconsistencies. Fixes #22257 --- src/core/service.c | 2 +- test/units/testsuite-51-repro-3.service | 10 ++++++++++ test/units/testsuite-51.sh | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/units/testsuite-51-repro-3.service diff --git a/src/core/service.c b/src/core/service.c index 88307fa1a5..905558af57 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1798,7 +1798,7 @@ static bool service_shall_restart(Service *s, const char **reason) { return false; case SERVICE_RESTART_ALWAYS: - return true; + return s->result != SERVICE_SKIP_CONDITION; case SERVICE_RESTART_ON_SUCCESS: return s->result == SERVICE_SUCCESS; diff --git a/test/units/testsuite-51-repro-3.service b/test/units/testsuite-51-repro-3.service new file mode 100644 index 0000000000..c68f93d11d --- /dev/null +++ b/test/units/testsuite-51-repro-3.service @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +[Unit] +Description=Issue 22257 Repro with Restart=always + +[Service] +Type=simple +Restart=always +ExecCondition=/bin/false +ExecStart=sleep 100 +RestartSec=1 diff --git a/test/units/testsuite-51.sh b/test/units/testsuite-51.sh index fbe9693f3a..e603d953a4 100755 --- a/test/units/testsuite-51.sh +++ b/test/units/testsuite-51.sh @@ -5,9 +5,11 @@ set -o pipefail systemctl start testsuite-51-repro-1 systemctl start testsuite-51-repro-2 +systemctl start testsuite-51-repro-3 sleep 5 # wait a bit in case there are restarts so we can count them below [[ "$(systemctl show testsuite-51-repro-1 -P NRestarts)" == "0" ]] [[ "$(systemctl show testsuite-51-repro-2 -P NRestarts)" == "0" ]] +[[ "$(systemctl show testsuite-51-repro-3 -P NRestarts)" == "0" ]] touch /testok From 429cddbaf1075ad235c2b74dd6eecc2dfd37f3ea Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 26 Jan 2022 19:03:34 +0000 Subject: [PATCH 2/2] NEWS: note breaking change w.r.t. Restart=always and ExecCondition= --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index 4551f82ffa..33bdbfe0a4 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,9 @@ CHANGES WITH 251: can still be used by explicitly configuring RouteTable= setting in .netdev files. + * Services with Restart=always and a failing ExecCondition= will no longer + be restarted, to bring ExecCondition= in line with Condition*= settings. + CHANGES WITH 250: * Support for encrypted and authenticated credentials has been added.