Debian Codegraph @

debian/kannel-bearerbox-waiter

raw
1 #!/bin/sh
2 #
3 # Copyright © 2025 Sipwise GmbH, Austria
4 #
5 # This file is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 # .
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, see <https://www.gnu.org/licenses/>.
17
18 set -e
19
20 conf=/etc/kannel/kannel.conf
21 addr="$(sed -ne 's/admin-interface *= *//p' $conf)"
22 addr="${addr:-127.0.0.1}"
23 port="$(sed -ne 's/admin-port *= *//p' $conf)"
24 url="$addr:$port/status"
25
26 timeout_http=10
27 timeout_func=20
28 timeout=0
29 delayinc=0.2
30
31
32 while [ $timeout -lt $timeout_http ] && ! GET -d "$url" ; do
33 sleep $delayinc
34 timeout=$((timeout + 1))
35 done
36
37 if [ $timeout -eq $timeout_http ]; then
38 exit 3
39 fi
40
41 timeout=0
42
43 while [ $timeout -lt $timeout_func ]; do
44 status="$(GET "$url" | sed -ne 's/^Status: \([a-z ]*\),.*$/\1/p' || true)"
45 case "$status" in
46 filled)
47 # Message queue full, retry.
48 ;;
49 running)
50 exit 0
51 ;;
52 suspended|isolated)
53 # Not accepting or receiving messages, not giving service.
54 exit 1
55 ;;
56 "going down")
57 # Shutting down or dead, not giving service.
58 exit 2
59 ;;
60 esac
61 sleep $delayinc
62 timeout=$((timeout + 1))
63 done
64
65 exit 3