Merge branch 'master' of ssh://sebmarque.hd.free.fr...
.../seb/scripts
... | ... |
@@ -1,9 +1,10 @@ |
1 | 1 |
#!/bin/bash |
2 | 2 |
|
3 | 3 |
basename=$(basename $0) |
4 |
-supervision_status="/dev/shm/${basename}${USER:+.$USER}.status" |
|
5 |
-supervision_disabled="/dev/shm/${basename}${USER:+.$USER}.disabled" |
|
6 |
-touch $supervision_status $supervision_disabled |
|
4 |
+monitoring_status="/dev/shm/${basename}${USER:+.$USER}.status" |
|
5 |
+monitoring_disabled="/dev/shm/${basename}${USER:+.$USER}.disabled" |
|
6 |
+monitoring_turns="/dev/shm/${basename}${USER:+.$USER}.turns" |
|
7 |
+touch $monitoring_status $monitoring_disabled $monitoring_turns |
|
7 | 8 |
now=$(date +%s) |
8 | 9 |
|
9 | 10 |
function _err () { |
... | ... |
@@ -26,7 +27,7 @@ function _load () { |
26 | 27 |
) |
27 | 28 |
for conf in $*; do |
28 | 29 |
count_loaded=0 |
29 |
- if grep -q "^@$conf$" $supervision_disabled; then |
|
30 |
+ if grep -q "^@$conf$" $monitoring_disabled; then |
|
30 | 31 |
disabled[${#disabled[@]}]=$conf |
31 | 32 |
else |
32 | 33 |
for dir in ${directories[@]}; do |
... | ... |
@@ -52,12 +53,17 @@ function _load () { |
52 | 53 |
fi |
53 | 54 |
} |
54 | 55 |
|
56 |
+function _turn () { |
|
57 |
+ test -n "$1" && [[ $1 =~ [0-9]+ ]] || return 1 |
|
58 |
+ echo ${FUNCNAME[1]} >> $monitoring_turns |
|
59 |
+ test $(( $(grep -c ${FUNCNAME[1]} $monitoring_turns) % $1 )) -eq 0 && sed -i "/^${FUNCNAME[1]}$/d" $monitoring_turns |
|
60 |
+} |
|
55 | 61 |
|
56 | 62 |
function _do_tests () { |
57 | 63 |
local t= |
58 | 64 |
for t in $(declare -f | sed -rn '/^[[:alpha:]]/s/^([[:alnum:]_]+)\s*\(\)\s*$/\1/p'); do |
59 | 65 |
local msg= |
60 |
- if grep -q "^${t}$" $supervision_disabled; then |
|
66 |
+ if grep -q "^${t}$" $monitoring_disabled; then |
|
61 | 67 |
echo supervision by $t disabled |
62 | 68 |
else |
63 | 69 |
msg=$( $t | sed 's/$/%0a/g' ) |
... | ... |
@@ -67,7 +73,7 @@ function _do_tests () { |
67 | 73 |
err[${#err[@]}]="${msg}" |
68 | 74 |
else |
69 | 75 |
if test -n "${!t}"; then |
70 |
- sed -ri "/^$t=.+$/d" $supervision_status |
|
76 |
+ sed -ri "/^$t=.+$/d" $monitoring_status |
|
71 | 77 |
fi |
72 | 78 |
fi |
73 | 79 |
fi |
... | ... |
@@ -75,7 +81,7 @@ function _do_tests () { |
75 | 81 |
} |
76 | 82 |
|
77 | 83 |
function _do_manage_errors () { |
78 |
- source $supervision_status |
|
84 |
+ source $monitoring_status |
|
79 | 85 |
local msg= |
80 | 86 |
local t= |
81 | 87 |
local errors= |
... | ... |
@@ -89,11 +95,11 @@ function _do_manage_errors () { |
89 | 95 |
errors="${errors}"'*'" [${t}] ${msg}" |
90 | 96 |
if test -n "${!t}"; then |
91 | 97 |
if test ${!t} -lt $(( $now - 86400 )); then |
92 |
- sed -ri "s/^(${t}=).+$/\1$now/" $supervision_status |
|
98 |
+ sed -ri "s/^(${t}=).+$/\1$now/" $monitoring_status |
|
93 | 99 |
let notification++ |
94 | 100 |
fi |
95 | 101 |
else |
96 |
- echo "${t}=$now" >> $supervision_status |
|
102 |
+ echo "${t}=$now" >> $monitoring_status |
|
97 | 103 |
let notification++ |
98 | 104 |
fi |
99 | 105 |
done |
... | ... |
@@ -8,18 +8,22 @@ function nginx () { |
8 | 8 |
} |
9 | 9 |
|
10 | 10 |
function searx () { |
11 |
+ _turn 5 || return |
|
11 | 12 |
nc -zw2 127.0.0.1 8888 || echo "injoignable sur port 8888" |
12 | 13 |
} |
13 | 14 |
|
14 | 15 |
function gitprep () { |
16 |
+ _turn 5 || return |
|
15 | 17 |
nc -zw2 127.0.0.1 10020 || echo "injoignable sur port 10020" |
16 | 18 |
} |
17 | 19 |
|
18 | 20 |
function cherrymusic () { |
21 |
+ _turn 5 || return |
|
19 | 22 |
nc -zw2 127.0.0.1 8080 || echo "injoignable sur port 8080" |
20 | 23 |
} |
21 | 24 |
|
22 | 25 |
function webapps () { |
26 |
+ _turn 3 || return # test toutes les 3 heures |
|
23 | 27 |
awk -v sq="'" ' |
24 | 28 |
/^[^#]+#\s*monitoring\s/ { |
25 | 29 |
if ($1 == "listen") { |