-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·66 lines (61 loc) · 2.93 KB
/
run.sh
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
64
65
66
#!/bin/bash
set -e
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
if [ "$1" = 'k8s' ]; then # For easy access through the Docker image without cloning the repo
cat "$HERE"/k8s/prep.sh
echo ""
echo "# Put the above script into a file and run it on your K8s control plane. Make the resulting files accessible to Logtfy."
exit
fi
if [ "$1" = 'role' ]; then # For easy access through the Docker image without cloning the repo
cat "$HERE"/k8s/role.yaml
echo ""
echo "# Put the above yaml into a file and run it on your K8s control plane."
exit
fi
trap "if [ -f "$HERE"/onExit.sh ]; then bash "$HERE"/onExit.sh; else bash "$HERE"/onExit.default.sh; fi; trap - SIGTERM && kill -- -\$\$ 2>/dev/null" EXIT
mkdir -p /tmp/logtfy # Semi-persistent storage used by some modules
for MODULE_REL_PATH in "$HERE"/modules/*; do
MODULE_ID="$(basename "$MODULE_REL_PATH")"
IS_ENABLED="$(node "$HERE"/configParser.js isModuleEnabled "$MODULE_ID")"
if [ "$IS_ENABLED" == true ]; then
LOGGER_EXTRA_DATA="$(node "$HERE"/configParser.js getLoggerArgForModule "$MODULE_ID")"
PARSER_EXTRA_DATA="$(node "$HERE"/configParser.js getParserArgForModule "$MODULE_ID")"
NTFY_CONFIGS="$(node "$HERE"/configParser.js getNtfyConfigsForModule "$MODULE_ID")"
MODULE_STRING="$(node "$HERE"/configParser.js getModuleSummaryString "$MODULE_ID" "$NTFY_CONFIGS")"
DEFAULT_PRIORITY="$(node "$HERE"/configParser.js getDefaultPriorityForModule "$MODULE_ID")"
DEFAULT_TAGS="$(node "$HERE"/configParser.js getDefaultTagsForModule "$MODULE_ID")"
MAX_FAILS="$(node "$HERE"/configParser.js getModuleAllowedFailCount)"
(
EXITED_CLEANLY=true
FAIL_COUNT=0
MAX_FAILS=3
while [ $MAX_FAILS -eq 0 ] || [ $FAIL_COUNT -lt $MAX_FAILS ]; do
TEMP_LOG_FILE="$(mktemp)"
echo "Running module: $MODULE_STRING..."
set -o pipefail
bash "$HERE"/runModule.sh "$MODULE_ID" "$LOGGER_EXTRA_DATA" "$PARSER_EXTRA_DATA" "$NTFY_CONFIGS" "$TEMP_LOG_FILE" "$DEFAULT_PRIORITY" "$DEFAULT_TAGS" || EXITED_CLEANLY=false
set +o pipefail
FAIL_COUNT=$((FAIL_COUNT + 1))
echo "
$(printf "%0.s=" $(seq 1 "$(tput cols 2>/dev/null || echo 10)"))
Module '$MODULE_ID' failed $FAIL_COUNT/$MAX_FAILS times. Log tail:
$(printf "%0.s-" $(seq 1 "$(tput cols 2>/dev/null || echo 10)"))
$(cat "$TEMP_LOG_FILE")
$(printf "%0.s=" $(seq 1 "$(tput cols 2>/dev/null || echo 10)"))
"
rm "$TEMP_LOG_FILE"
done
if [ -f "$HERE"/onModuleExit.sh ]; then
bash "$HERE"/onModuleExit.sh "$MODULE_ID" "$EXITED_CLEANLY"
else
bash "$HERE"/onModuleExit.default.sh "$MODULE_ID" "$EXITED_CLEANLY"
fi
) &
fi
done
if [ "$(node "$HERE"/configParser.js shouldCatchModuleCrashes)" = true ]; then
wait
else
wait -n
fi