core/service: actually allow to "hurry up" auto restarts
unit_start() advertises that start requests don't get suppressed, so that it could be used to manually speed up auto restarts. However, service_start() so far rejected this, stating that clients should issue restart request in order to trigger BindsTo=/OnFailure=. That seems to be a red herring though, because for a long time the service states between auto-restarts were buggy (#27594). With the introduction of RestartMode=direct, the behavior is sane again and customizable, hence I see no reason to refuse this anymore. Whether those deps are triggered solely depends on RestartMode= now. Plus, filter out some intermediate states that should never be seen in service_start(). Fixes #33890
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
# shellcheck disable=SC2016
|
||||
|
||||
set -eux
|
||||
set -o pipefail
|
||||
|
||||
@@ -166,4 +168,30 @@ assert_rc 3 systemctl --quiet is-active succeeds-on-restart.target
|
||||
systemctl start fails-on-restart.target || :
|
||||
assert_rc 3 systemctl --quiet is-active fails-on-restart.target
|
||||
|
||||
# Test shortcutting auto restart
|
||||
|
||||
export UNIT_NAME="TEST-03-JOBS-shortcut-restart.service"
|
||||
TMP_FILE="/tmp/test-03-shortcut-restart-test$RANDOM"
|
||||
|
||||
cat >"/run/systemd/system/$UNIT_NAME" <<EOF
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=rm -v "$TMP_FILE"
|
||||
Restart=on-failure
|
||||
RestartSec=1d
|
||||
RemainAfterExit=yes
|
||||
EOF
|
||||
|
||||
(! systemctl start "$UNIT_NAME")
|
||||
timeout 10 bash -c 'while [[ "$(systemctl show "$UNIT_NAME" -P SubState)" != "auto-restart" ]]; do sleep .5; done'
|
||||
touch "$TMP_FILE"
|
||||
assert_eq "$(systemctl show "$UNIT_NAME" -P SubState)" "auto-restart"
|
||||
|
||||
timeout 30 systemctl start "$UNIT_NAME"
|
||||
systemctl --quiet is-active "$UNIT_NAME"
|
||||
assert_eq "$(systemctl show "$UNIT_NAME" -P NRestarts)" "1"
|
||||
[[ ! -f "$TMP_FILE" ]]
|
||||
|
||||
rm /run/systemd/system/"$UNIT_NAME"
|
||||
|
||||
touch /testok
|
||||
|
||||
Reference in New Issue
Block a user