-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-services
62 lines (50 loc) · 1.18 KB
/
03-services
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
#!/bin/bash
source /etc/update-motd.d/colors.txt
declare -a services=(
"cron"
"systemd-timesyncd"
"nginx"
"postgresql"
"redis-server"
"grafana-agent"
"minecraft"
)
declare -a serviceName=(
"CRON"
"NTP"
"Nginx"
"PostgreSQL"
"Redis"
"Grafana"
"Minecraft"
)
declare -a serviceStatus=()
# Get service status
for service in "${services[@]}"
do
serviceStatus+=($(systemctl is-active "$service.service"))
done
# Max column width
width=$((64-2))
line=" Service Status......: "
for i in ${!serviceStatus[@]}
do
# Next line and next line length
next=" ${serviceName[$i]}: \e[5m${serviceStatus[$i]}"
nextLen=$((1+${#next}))
# If the current line will exceed the max column with then echo the current line and start a new line
if [[ $((lineLen+nextLen)) -gt width ]]; then
echo -e "$line"
lineLen=0
line=" "
fi
lineLen=$((lineLen+nextLen))
# Color the next line green if it's active, else red
if [[ "${serviceStatus[$i]}" == "active" ]]; then
line+="\e[32m\e[0m${serviceName[$i]}: \e[32m● ${serviceStatus[$i]}\e[0m "
else
line+="${serviceName[$i]}: \e[31m▲ ${serviceStatus[$i]}\e[0m "
fi
done
# echo what is left
echo -e "$line"