-
Notifications
You must be signed in to change notification settings - Fork 0
/
statman.sh
executable file
·72 lines (57 loc) · 1.73 KB
/
statman.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
67
68
69
70
71
72
#! /usr/bin/env bash
set -e
# This should be available in all scripts
export statman_dir="$(dirname -- "$0")"
echo "STARTING STATMAN"
# Include helpers and shared values
source $statman_dir/shared.sh
# Include runtime functions
source $statman_dir/runtimes.sh
# Include primary render function (if not in exec mode)
if [[ -z "${STATMAN_EXEC_RENDER}" ]]; then
source $statman_dir/render.sh
else
echo "-> Execution mode detection, do not forget to disable when done"
fi
# START INIT
# Ensure that subprocesses exit as expected
trap "trap - SIGTERM && kill -- -$$" INT TERM EXIT
echo "-> Initiating memstore"
# create mem store directory if it does not exist already
mkdir -p "$statman_readout_directory" || true
echo "-> Launching subroutines"
# boot each subshell process
statman_every_half_second &
statman_every_second &
statman_every_two_seconds &
statman_every_five_seconds &
statman_every_minute &
statman_every_five_minutes &
echo "-> Initiating primary render loop"
# hide cursor
printf '\e[?25l'
sleep 1
echo "-> Ready for stats"
# Render loop executes below - to change the output, go to render.sh
if [[ ! -z "${STATMAN_EXEC_RENDER}" ]]; then
# exec renderer mode (best for testing)
while true; do
# minimum wait time for each render iteration
sleep .25 &
output="$(sh $statman_dir/render.sh)"
# set cursor to start
echo "$output"
# waits for the sleep (ensuring min duration)
wait $!
done
else
# direct renderer mode (best for live)
while true; do
# minimum wait time for each render iteration
sleep .25 &
# set cursor to front
echo "$(render)"
# waits for the sleep (ensuring min duration)
wait $!
done
fi