... | ... |
@@ -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") { |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-#!/usr/bin/awk -f |
|
1 |
+#!/usr/bin/gawk -f |
|
2 | 2 |
|
3 | 3 |
function evaluate (str) { |
4 | 4 |
for (j = 1; j <= length(str); j++) { |
... | ... |
@@ -35,19 +35,35 @@ function print_version () { |
35 | 35 |
printf("%s version %s\n", appname, version) |
36 | 36 |
} |
37 | 37 |
|
38 |
+function cli_error (rc) { |
|
39 |
+ print "CLI error: " rc |
|
40 |
+ exit 1 |
|
41 |
+} |
|
42 |
+ |
|
38 | 43 |
function help (rc) { |
39 |
- print_version() |
|
40 |
- if (rc != "") { |
|
41 |
- print "CLI error: " rc |
|
42 |
- exit 1 |
|
44 |
+ line = appname "\nversion " version "\n\n\033[4mOPTIONS:\033[0m" |
|
45 |
+ while (getline < appname) { |
|
46 |
+ if (/^#help:BEGIN/) help_started = 1 |
|
47 |
+ if (/^#help:END/) help_started = 0 |
|
48 |
+ if (help_started) { |
|
49 |
+ if (/^[[:blank:]]*case \/\^(.+)\$\/[[:blank:]]*\:[[:blank:]]*$/) { |
|
50 |
+ option = gensub(/^[[:blank:]]*case \/\^(.+)\$\/[[:blank:]]*\:[[:blank:]]*$/, "\\1", "1") |
|
51 |
+ line = line "\n\n\033[1m" option "\033[0m" |
|
52 |
+ } |
|
53 |
+ else if (/^#help:/ && option != "") { |
|
54 |
+ split($0, helpinfo, ":") |
|
55 |
+ line = line "\n" helpinfo[2] |
|
56 |
+ } |
|
57 |
+ } |
|
43 | 58 |
} |
59 |
+ print line | "pager -R" |
|
44 | 60 |
exit 0 |
45 | 61 |
} |
46 | 62 |
|
47 | 63 |
BEGIN { |
48 | 64 |
# initialisation |
49 | 65 |
appname = ENVIRON["_"] |
50 |
- version = "0.9" |
|
66 |
+ version = "1.0.0" |
|
51 | 67 |
conf_arrays = "" |
52 | 68 |
filename = "" |
53 | 69 |
sections = "" |
... | ... |
@@ -68,67 +84,89 @@ BEGIN { |
68 | 84 |
|
69 | 85 |
for (arg = 1; arg < ARGC; arg++) |
70 | 86 |
switch (ARGV[arg]) { |
87 |
+#help:BEGIN |
|
71 | 88 |
case /^--conf=["']?.+["']?$/: |
89 |
+#help:file containing the configuration to read |
|
72 | 90 |
filename = gensub(/^--conf=["']?(.+)["']?$/, "\\1", "", ARGV[arg]) |
73 | 91 |
break |
74 | 92 |
case /^--conf$/: |
93 |
+#help:file containing the configuration to read |
|
75 | 94 |
filename = gensub(/^["']?(.+)["']?$/, "\\1", "", ARGV[++arg]) |
76 | 95 |
break |
77 | 96 |
case "--sections-list": |
97 |
+#help:list all sections found in given config file |
|
78 | 98 |
returnsectionlist = 1 |
79 | 99 |
break |
80 | 100 |
case /^--section=["']?.+["']?$/: |
101 |
+#help:retrieve information for section <section> |
|
81 | 102 |
s = gensub(/^--section=["']?(.+)["']?$/, "\\1", "", ARGV[arg]) |
82 | 103 |
onlysections[s] = true |
83 | 104 |
break |
84 |
- case /^-s$/: |
|
85 |
- s = gensub(/^["']?(.+)["']?$/, "\\1", "", ARGV[++arg]) |
|
86 |
- onlysections[s] = true |
|
87 |
- break |
|
105 |
+# case /^-s$/: |
|
106 |
+##help:retrieve information for section <section> |
|
107 |
+# s = gensub(/^["']?(.+)["']?$/, "\\1", "", ARGV[++arg]) |
|
108 |
+# onlysections[s] = true |
|
109 |
+# break |
|
88 | 110 |
case /^--clean$/: |
111 |
+#help:output commands to clean all variables listed in configuration |
|
89 | 112 |
clean = true |
90 | 113 |
break |
91 | 114 |
case /^--unset$/: |
115 |
+#help:output commands to unset variables listed in configuration file |
|
92 | 116 |
unset = true |
93 | 117 |
break |
94 | 118 |
case /^--compact$/: |
119 |
+#help:output everything on a single line, elements seperated by semi-colon |
|
95 | 120 |
eol = ";" |
96 | 121 |
break |
97 | 122 |
case /^--array=["']?.+["']?$/: |
123 |
+#help:learns the script this entry is intented to be treated as an array, can be used multiple times for multiples array names |
|
98 | 124 |
arrayname=gensub(/^--array=["']?(.+)["']?$/, "\\1", "", ARGV[arg]) |
99 | 125 |
conf_arrays = conf_arrays "|" arrayname |
100 | 126 |
key_array[arrayname]++ |
101 | 127 |
break |
102 | 128 |
case /^--first-element-array=[01]$/: |
129 |
+#help:tells the script the array index begins at 0 or 1, defaults to 0 |
|
103 | 130 |
first_element_index = gensub(/^--first-element-array=([01])$/, "\\1", "", ARGV[arg]) |
104 | 131 |
break |
105 | 132 |
case /^--var-delim-begin=["']?.{3,}["']?$/: |
133 |
+#help:tells the script what is the starting chars sequence to delimitate a variable, defaults to {{{, can be -+= (for example) |
|
106 | 134 |
var_delimiters_begin = gensub(/^--var-delim-begin=["']?(.{3,})["']?$/, "\\1", "", ARGV[arg]) |
107 | 135 |
break |
108 | 136 |
case /^--var-delim-end=["']?.{3,}["']?$/: |
137 |
+#help:tells the script what is the ending chars sequence to delimitate a variable, defaults to }}}, can be =+- (for example) |
|
109 | 138 |
var_delimiters_end = gensub(/^--var-delim-end=["']?(.{3,})["']?$/, "\\1", "", ARGV[arg]) |
110 | 139 |
break |
111 | 140 |
case /^--case-sensitive$/: |
141 |
+#help:tells the script if it has to be case-sensitive, defaults to insensitive |
|
112 | 142 |
case_sensitive = true |
113 | 143 |
break |
114 | 144 |
case /^--case-insensitive(|=lower|=UPPER)$/: |
145 |
+#help:tells the script how to behave in insensitive mode (default) |
|
146 |
+#help: lower = variables output in lowercase (default) |
|
147 |
+#help: UPPER = variables output in UPPERCASE |
|
115 | 148 |
case_sensitive = false |
116 | 149 |
default_case = gensub(/^--case-insensitive[=]?(.*)$/, "\\1", "", ARGV[arg]) |
117 | 150 |
if (default_case == "") |
118 | 151 |
default_case = "lower" |
119 | 152 |
break |
120 | 153 |
case /^--key-value-delimiter=["']?.["']?$/: |
154 |
+#help:tells the script which char is used to separate the key from its assorciated value in the configuration file, defaults to blank-char |
|
121 | 155 |
key_value_delimiter = gensub(/^--key-value-delimiter=["']?(.)["']?$/, "\\1", "", ARGV[arg]) |
122 | 156 |
break |
123 | 157 |
case /^--in-var-space-replacement=["']?.["']?$/: |
158 |
+#help:tells the script which char to use to replace a space found in a key, defaults to empty |
|
124 | 159 |
in_var_space_remplacement = gensub(/^--in-var-space-replacement=["']?(.)["']?$/, "\\1", "", ARGV[arg]) |
125 | 160 |
break |
126 | 161 |
case /^help$/: |
162 |
+#help:show this help |
|
127 | 163 |
help() |
128 | 164 |
break |
129 | 165 |
case /^version$/: |
166 |
+#help:show the version of the script |
|
130 | 167 |
print_version() |
131 | 168 |
exit |
169 |
+#help:END |
|
132 | 170 |
default: |
133 | 171 |
help(ARGV[arg]) |
134 | 172 |
} |