summaryrefslogtreecommitdiffstats
path: root/test/TEST-16-EXTEND-TIMEOUT/TEST-16-EXTEND-TIMEOUT.units/extend-timeout.sh
blob: 45a18b93b5fda0dc152fa8c5d0b52d8125af13a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eux
set -o pipefail

# sleep interval (seconds)
sleep_interval="${sleep_interval:-1}"
# extend_timeout_interval second(s)
extend_timeout_interval="${extend_timeout_interval:-1}"
# number of sleep_intervals before READY=1
start_intervals="${start_intervals:-10}"
# number of sleep_intervals before exiting
stop_intervals="${stop_intervals:-10}"
# run intervals, number of sleep_intervals to run
run_intervals="${run_intervals:-7}"

# We convert to usec
extend_timeout_interval=$((extend_timeout_interval * 1000000))

# shellcheck disable=SC2064
trap "{ touch /${SERVICE}.terminated; exit 1; }" SIGTERM SIGABRT

rm -f "/${SERVICE}".*
touch "/${SERVICE}.startfail"

systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval"
while [[ $start_intervals -gt 0 ]]
do
    sleep "$sleep_interval"
    start_intervals=$((start_intervals - 1))
    systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval"
done

systemd-notify --ready --status="Waiting for your request"

touch "/${SERVICE}.runtimefail"
rm "/${SERVICE}.startfail"

systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval"
while [[ $run_intervals -gt 0 ]]
do
    sleep "$sleep_interval"
    run_intervals=$((run_intervals - 1))
    systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval"
done

systemd-notify STOPPING=1

touch "/${SERVICE}.stopfail"
rm "/${SERVICE}.runtimefail"

systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval"
while [[ $stop_intervals -gt 0 ]]
do
    sleep "$sleep_interval"
    stop_intervals=$((stop_intervals - 1))
    systemd-notify EXTEND_TIMEOUT_USEC="$extend_timeout_interval"
done

touch "/${SERVICE}.success"
rm "/${SERVICE}.stopfail"

exit 0