| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 | # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- |
| 4 | # ex: ts=8 sw=4 sts=4 et filetype=sh |
| 5 | set -eux |
| 6 | set -o pipefail |
| 7 | |
| 8 | # Test start & stop operations without daemon-reload |
| 9 | |
| 10 | at_exitscip-shell shell systemd 261~rc4-1 at_exit().() { |
| 11 | set +e |
| 12 | |
| 13 | rmscip-shell system . . rm. -f /run/systemd/system/TEST-23-UNIT-FILE-no-reload.targetscip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.target`. |
| 14 | rmscip-shell system . . rm. -f /run/systemd/system/TEST-23-UNIT-FILE-no-reload.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.service`. |
| 15 | rmscip-shell system . . rm. -f /run/systemd/system/TEST-23-UNIT-FILE-no-reload-2.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload-2.service`. |
| 16 | rmscip-shell system . . rm. -f /run/systemd/system/TEST-23-UNIT-FILE-no-reload-3.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload-3.service`. |
| 17 | systemctl stop TEST-23-UNIT-FILE-no-reload.target |
| 18 | systemctl stop TEST-23-UNIT-FILE-no-reload.service |
| 19 | systemctl stop TEST-23-UNIT-FILE-no-reload-2.service |
| 20 | systemctl stop TEST-23-UNIT-FILE-no-reload-3.service |
| 21 | } |
| 22 | |
| 23 | trap at_exit EXIT |
| 24 | |
| 25 | catscip-shell system . . cat. >/run/systemd/system/TEST-23-UNIT-FILE-no-reload.targetscip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.target`. <<EOF |
| 26 | [Unit] |
| 27 | Wants=TEST-23-UNIT-FILE-no-reload.service |
| 28 | EOF |
| 29 | |
| 30 | systemctl daemon-reload |
| 31 | |
| 32 | systemctl start TEST-23-UNIT-FILE-no-reload.target |
| 33 | |
| 34 | # The filesystem on the test image, despite being ext4, seems to have a mtime |
| 35 | # granularity of one second, which means the manager's unit cache won't be |
| 36 | # marked as dirty when writing the unit file, unless we wait at least a full |
| 37 | # second after the previous daemon-reload. |
| 38 | # May 07 23:12:20 H TEST-23-UNIT-FILE.sh[30]: + cat |
| 39 | # May 07 23:12:20 H TEST-23-UNIT-FILE.sh[30]: + ls -l --full-time /etc/systemd/system/TEST-23-UNIT-FILE-no-reload.service |
| 40 | # May 07 23:12:20 H TEST-23-UNIT-FILE.sh[52]: -rw-r--r-- 1 root root 50 2020-05-07 23:12:20.000000000 +0100 / |
| 41 | # May 07 23:12:20 H TEST-23-UNIT-FILE.sh[30]: + stat -f --format=%t /etc/systemd/system/TEST-23-UNIT-FILE-no-reload.servic |
| 42 | # May 07 23:12:20 H TEST-23-UNIT-FILE.sh[53]: ef53 |
| 43 | sleepscip-shell system . . sleep. 3.1 |
| 44 | |
| 45 | catscip-shell system . . cat. >/run/systemd/system/TEST-23-UNIT-FILE-no-reload.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.service`. <<EOF |
| 46 | [Service] |
| 47 | ExecStart=sleep infinity |
| 48 | EOF |
| 49 | |
| 50 | systemctl start TEST-23-UNIT-FILE-no-reload.service |
| 51 | |
| 52 | systemctl is-active TEST-23-UNIT-FILE-no-reload.service |
| 53 | |
| 54 | # Stop and remove, and try again to exercise https://github.com/systemd/systemd/issues/15992 |
| 55 | systemctl stop TEST-23-UNIT-FILE-no-reload.service |
| 56 | rmscip-shell system . . rm. -f /run/systemd/system/TEST-23-UNIT-FILE-no-reload.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.service`. |
| 57 | systemctl daemon-reload |
| 58 | |
| 59 | sleepscip-shell system . . sleep. 3.1 |
| 60 | |
| 61 | catscip-shell system . . cat. >/run/systemd/system/TEST-23-UNIT-FILE-no-reload.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.service`. <<EOF |
| 62 | [Service] |
| 63 | ExecStart=sleep infinity |
| 64 | EOF |
| 65 | |
| 66 | # Start a non-existing unit first, so that the cache is reloaded for an unrelated |
| 67 | # reason. Starting the existing unit later should still work thanks to the check |
| 68 | # for the last load attempt vs cache timestamp. |
| 69 | systemctl start TEST-23-UNIT-FILE-no-reload-nonexistent.service || truescip-shell system . . true. |
| 70 | |
| 71 | systemctl start TEST-23-UNIT-FILE-no-reload.service |
| 72 | |
| 73 | systemctl is-active TEST-23-UNIT-FILE-no-reload.service |
| 74 | |
| 75 | # Stop and remove, and try again to exercise the transaction setup code path by |
| 76 | # having the target pull in the unloaded but available unit |
| 77 | systemctl stop TEST-23-UNIT-FILE-no-reload.service TEST-23-UNIT-FILE-no-reload.target |
| 78 | rmscip-shell system . . rm. -f /run/systemd/system/TEST-23-UNIT-FILE-no-reload.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.service`. /run/systemd/system/TEST-23-UNIT-FILE-no-reload.targetscip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.target`. |
| 79 | systemctl daemon-reload |
| 80 | |
| 81 | sleepscip-shell system . . sleep. 3.1 |
| 82 | |
| 83 | catscip-shell system . . cat. >/run/systemd/system/TEST-23-UNIT-FILE-no-reload.targetscip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.target`. <<EOF |
| 84 | [Unit] |
| 85 | Conflicts=shutdown.target |
| 86 | Wants=TEST-23-UNIT-FILE-no-reload.service |
| 87 | EOF |
| 88 | |
| 89 | systemctl daemon-reload |
| 90 | |
| 91 | systemctl start TEST-23-UNIT-FILE-no-reload.target |
| 92 | |
| 93 | catscip-shell system . . cat. >/run/systemd/system/TEST-23-UNIT-FILE-no-reload.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.service`. <<EOF |
| 94 | [Service] |
| 95 | ExecStart=sleep infinity |
| 96 | EOF |
| 97 | |
| 98 | systemctl restart TEST-23-UNIT-FILE-no-reload.target |
| 99 | |
| 100 | systemctl is-active TEST-23-UNIT-FILE-no-reload.service |
| 101 | |
| 102 | # Stop and remove, and try again to exercise https://github.com/systemd/systemd/issues/36031 |
| 103 | systemctl stop TEST-23-UNIT-FILE-no-reload.service TEST-23-UNIT-FILE-no-reload.target |
| 104 | rmscip-shell system . . rm. -f /run/systemd/system/TEST-23-UNIT-FILE-no-reload.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.service`. /run/systemd/system/TEST-23-UNIT-FILE-no-reload.targetscip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.target`. |
| 105 | systemctl daemon-reload |
| 106 | |
| 107 | sleepscip-shell system . . sleep. 3.1 |
| 108 | |
| 109 | catscip-shell system . . cat. >/run/systemd/system/TEST-23-UNIT-FILE-no-reload.targetscip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.target`. <<EOF |
| 110 | [Unit] |
| 111 | Conflicts=shutdown.target |
| 112 | EOF |
| 113 | |
| 114 | catscip-shell system . . cat. >/run/systemd/system/TEST-23-UNIT-FILE-no-reload.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload.service`. <<EOF |
| 115 | [Unit] |
| 116 | Conflicts=TEST-23-UNIT-FILE-no-reload.target |
| 117 | Wants=TEST-23-UNIT-FILE-no-reload-2.service |
| 118 | Wants=TEST-23-UNIT-FILE-no-reload-3.service |
| 119 | [Service] |
| 120 | ExecStart=sleep infinity |
| 121 | EOF |
| 122 | |
| 123 | systemctl daemon-reload |
| 124 | |
| 125 | systemctl start TEST-23-UNIT-FILE-no-reload.service |
| 126 | (! systemctl is-active TEST-23-UNIT-FILE-no-reload.target ) |
| 127 | systemctl is-active TEST-23-UNIT-FILE-no-reload.service |
| 128 | [[ "$(systemctl show --property LoadState --value TEST-23-UNIT-FILE-no-reload-2.service)" == not-found ]] |
| 129 | [[ "$(systemctl show --property LoadState --value TEST-23-UNIT-FILE-no-reload-3.service)" == not-found ]] |
| 130 | |
| 131 | catscip-shell system . . cat. >/run/systemd/system/TEST-23-UNIT-FILE-no-reload-2.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload-2.service`. <<EOF |
| 132 | [Unit] |
| 133 | Conflicts=TEST-23-UNIT-FILE-no-reload.target |
| 134 | [Service] |
| 135 | ExecStart=sleep infinity |
| 136 | EOF |
| 137 | |
| 138 | # This service file is intentionally invalid (Type=exec without ExecStart=). |
| 139 | catscip-shell system . . cat. >/run/systemd/system/TEST-23-UNIT-FILE-no-reload-3.servicescip-shell filesystem . . `/run/systemd/system/TEST-23-UNIT-FILE-no-reload-3.service`. <<EOF |
| 140 | [Unit] |
| 141 | Conflicts=TEST-23-UNIT-FILE-no-reload.target |
| 142 | [Service] |
| 143 | Type=exec |
| 144 | ExecStop=sleep infinity |
| 145 | EOF |
| 146 | |
| 147 | systemctl start TEST-23-UNIT-FILE-no-reload.target |
| 148 | systemctl is-active TEST-23-UNIT-FILE-no-reload.target |
| 149 | (! systemctl is-active TEST-23-UNIT-FILE-no-reload.service ) |
| 150 | (! systemctl is-active TEST-23-UNIT-FILE-no-reload-2.service ) |
| 151 | (! systemctl is-active TEST-23-UNIT-FILE-no-reload-3.service ) |
| 152 | [[ "$(systemctl show --property LoadState --value TEST-23-UNIT-FILE-no-reload-2.service)" == loaded ]] |
| 153 | [[ "$(systemctl show --property LoadState --value TEST-23-UNIT-FILE-no-reload-3.service)" == bad-setting ]] |
| 154 | [[ "$(systemctl show --property Conflicts --value TEST-23-UNIT-FILE-no-reload-2.service)" =~ TEST-23-UNIT-FILE-no-reload.target ]] |
| 155 | [[ "$(systemctl show --property Conflicts --value TEST-23-UNIT-FILE-no-reload-3.service)" =~ TEST-23-UNIT-FILE-no-reload.target ]] |