Annotation of /mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in
Parent Directory | Revision Log
Revision 2005 -
(hide annotations)
(download)
Mon Aug 13 09:38:21 2012 UTC (11 years, 9 months ago) by niro
Original Path: mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class
File size: 6658 byte(s)
Mon Aug 13 09:38:21 2012 UTC (11 years, 9 months ago) by niro
Original Path: mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class
File size: 6658 byte(s)
-added stop_service() function
1 | niro | 1248 | # $Id$ |
2 | |||
3 | niro | 1915 | # loads client classes from $MCLIBDIR |
4 | load_client_classes() | ||
5 | { | ||
6 | # client specific | ||
7 | for i in ${MCLIBDIR}/include/*.client.class | ||
8 | do | ||
9 | source ${i} || eecho "error loading ${i}" | ||
10 | done | ||
11 | } | ||
12 | |||
13 | # restarts the whole service via remote cmd | ||
14 | restart_service() | ||
15 | { | ||
16 | local pid | ||
17 | for pid in $(pidof sslsvd) | ||
18 | do | ||
19 | kill -SIGHUP ${pid} | ||
20 | done | ||
21 | } | ||
22 | |||
23 | niro | 2005 | # stops the whole service via remote cmd |
24 | stop_service() | ||
25 | { | ||
26 | local pid | ||
27 | for pid in $(pidof sslsvd) | ||
28 | do | ||
29 | kill -15 ${pid} | ||
30 | sleep 1 | ||
31 | kill -9 ${pid} | ||
32 | done | ||
33 | } | ||
34 | |||
35 | niro | 1252 | # # import_resource $table $serial $resource $value |
36 | # import_resource() | ||
37 | # { | ||
38 | # local table="$1" | ||
39 | # local serial="$2" | ||
40 | # local resource="$3" | ||
41 | # local value="$4" | ||
42 | # | ||
43 | # if [[ ${DEBUG} = 1 ]] | ||
44 | # then | ||
45 | # echo "${table}->${resource}=${value}" >> /root/lala.log | ||
46 | # echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log | ||
47 | # fi | ||
48 | # | ||
49 | # mysql_insert "${table}",serial="${serial}","${resource}"="${value}" | ||
50 | # } | ||
51 | niro | 1248 | |
52 | # run_class $method $caller $argv1 $argv2 ... $argvN | ||
53 | run_class() | ||
54 | { | ||
55 | local method="$1" | ||
56 | local caller="$2" | ||
57 | local class | ||
58 | local cmd | ||
59 | local argv | ||
60 | |||
61 | niro | 1308 | if valid_session |
62 | niro | 1248 | then |
63 | class="${caller%.*}" | ||
64 | cmd="${caller#*.}" | ||
65 | argv="${@/${caller}/}" # remove caller | ||
66 | argv="${argv/${method}/}" # remove method | ||
67 | |||
68 | # echo "method=${method}" | ||
69 | # echo "caller=${caller}" | ||
70 | # echo "class=${class}" | ||
71 | # echo "cmd=${cmd}" | ||
72 | # echo "argv=${argv}" | ||
73 | |||
74 | # check if class.cmd exist | ||
75 | if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]] | ||
76 | then | ||
77 | "${method}"_"${class}"_"${cmd}" ${argv} | ||
78 | else | ||
79 | niro | 1639 | eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'" |
80 | niro | 1248 | fi |
81 | else | ||
82 | invalid_session | ||
83 | fi | ||
84 | } | ||
85 | |||
86 | help_topics() | ||
87 | { | ||
88 | local i | ||
89 | local topics | ||
90 | |||
91 | topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) | ||
92 | mecho "Global commands:" | ||
93 | niro | 1350 | mecho "\timport - import settings to database" |
94 | mecho "\tget - shows current value for a settings" | ||
95 | mecho "\tset - sets value for a setting" | ||
96 | mecho "\tauth - authenticate to the daemon" | ||
97 | mecho "\tprovide - shows provides of a system" | ||
98 | mecho "\trequire - verify plugin requirements" | ||
99 | niro | 1925 | mecho "\treload - reloads all client classes plugins" |
100 | mecho "\trestart - restarts the daemon" | ||
101 | niro | 2005 | mecho "\tstop - stops the daemon" |
102 | niro | 1330 | mecho "\tnocolors - disable colors, useful for the webclient" |
103 | niro | 1639 | mecho "\tquiet - do not print any unecessary messages" |
104 | niro | 1350 | mecho "\thelp - shows help" |
105 | mecho "\tquit - quits the connection to the server" | ||
106 | niro | 1248 | mecho |
107 | mecho "Help topics:" | ||
108 | for i in ${topics} | ||
109 | do | ||
110 | # excludes | ||
111 | case ${i} in | ||
112 | help_topics|topics) continue ;; | ||
113 | esac | ||
114 | |||
115 | mecho "\t${i}" | ||
116 | done | ||
117 | niro | 1264 | mecho |
118 | mecho "Type 'help [topic]' for more information about every topic." | ||
119 | niro | 1248 | } |
120 | |||
121 | # on newer xorg-servers root is not allowed to run progs in a user session | ||
122 | x11runas() | ||
123 | { | ||
124 | niro | 1666 | if [[ -n $(pidof X) ]] |
125 | niro | 1639 | then |
126 | su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@" | ||
127 | fi | ||
128 | niro | 1248 | } |
129 | |||
130 | addconfig() | ||
131 | { | ||
132 | niro | 1308 | local opts |
133 | |||
134 | niro | 1248 | if [[ -z ${CONFIG} ]] |
135 | then | ||
136 | niro | 1639 | eecho "You must define \$CONFIG varibale first!" |
137 | niro | 1248 | return 1 |
138 | fi | ||
139 | |||
140 | if [[ ! -d $(dirname ${CONFIG}) ]] | ||
141 | then | ||
142 | install -d $(dirname ${CONFIG}) | ||
143 | fi | ||
144 | niro | 1308 | |
145 | # check for opts | ||
146 | case $1 in | ||
147 | -n) shift; opts=" -n" ;; | ||
148 | -e) shift; opts=" -e" ;; | ||
149 | esac | ||
150 | |||
151 | echo ${opts} "$@" >> ${CONFIG} | ||
152 | niro | 1248 | } |
153 | |||
154 | clearconfig() | ||
155 | { | ||
156 | if [[ -z ${CONFIG} ]] | ||
157 | then | ||
158 | niro | 1639 | eecho "You must define \$CONFIG varibale first!" |
159 | niro | 1248 | return 1 |
160 | fi | ||
161 | |||
162 | niro | 1252 | if [[ ! -d $(dirname ${CONFIG}) ]] |
163 | then | ||
164 | install -d $(dirname ${CONFIG}) | ||
165 | fi | ||
166 | niro | 1248 | : > ${CONFIG} |
167 | } | ||
168 | |||
169 | niro | 1264 | # no_duplicate $list $item |
170 | no_duplicate() | ||
171 | { | ||
172 | local i | ||
173 | local list="$1" | ||
174 | local item="$2" | ||
175 | |||
176 | for i in ${list} | ||
177 | do | ||
178 | [[ ${i} = ${item} ]] && return 1 | ||
179 | done | ||
180 | |||
181 | return 0 | ||
182 | } | ||
183 | |||
184 | niro | 1248 | require() |
185 | { | ||
186 | local requires="$@" | ||
187 | local i | ||
188 | |||
189 | for i in ${requires} | ||
190 | do | ||
191 | niro | 1264 | # check for duplicate provides |
192 | if no_duplicate "${PROVIDE}" "${i}" | ||
193 | then | ||
194 | export REQUIRE="${REQUIRE} ${i}" | ||
195 | else | ||
196 | niro | 1639 | decho "duplicate provide '${i}' detected!" |
197 | niro | 1264 | fi |
198 | niro | 1248 | done |
199 | } | ||
200 | |||
201 | niro | 1264 | verify_requirements() |
202 | niro | 1248 | { |
203 | niro | 1264 | local req |
204 | local prov | ||
205 | local missing | ||
206 | local sorted | ||
207 | niro | 1248 | |
208 | niro | 1264 | for req in ${REQUIRE} |
209 | niro | 1248 | do |
210 | niro | 1264 | # scan PROVIDE for dupes |
211 | # if a dupe is found, then requirement is fullfilled | ||
212 | # else add to missing | ||
213 | if no_duplicate "${PROVIDE}" "${req}" | ||
214 | then | ||
215 | missing="${missing} ${req}" | ||
216 | fi | ||
217 | niro | 1248 | done |
218 | |||
219 | niro | 1264 | # sort them alpabetically |
220 | sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort) | ||
221 | |||
222 | # show missing and set the right retval | ||
223 | if [[ -z ${missing} ]] | ||
224 | then | ||
225 | niro | 1639 | rvecho "${sorted}" |
226 | niro | 1264 | return 0 |
227 | else | ||
228 | for req in ${sorted} | ||
229 | do | ||
230 | if no_duplicate "${missing}" "$req" | ||
231 | then | ||
232 | # print normal | ||
233 | niro | 1639 | rvecho -n " ${req}" |
234 | niro | 1264 | else |
235 | # print missing | ||
236 | eecho -n " ${req}" | ||
237 | fi | ||
238 | done | ||
239 | return 1 | ||
240 | fi | ||
241 | niro | 1248 | } |
242 | |||
243 | provide() | ||
244 | { | ||
245 | local provides="$@" | ||
246 | local i | ||
247 | |||
248 | for i in ${provides} | ||
249 | do | ||
250 | # check for duplicate provides | ||
251 | niro | 1264 | if no_duplicate "${PROVIDE}" "${i}" |
252 | niro | 1248 | then |
253 | export PROVIDE="${PROVIDE} ${i}" | ||
254 | else | ||
255 | niro | 1639 | decho "duplicate provide '${i}' detected!" |
256 | niro | 1248 | fi |
257 | done | ||
258 | } | ||
259 | |||
260 | print_provide() | ||
261 | { | ||
262 | local sorted | ||
263 | |||
264 | # sort them alpabetically | ||
265 | sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) | ||
266 | # do not escape, or CRLFS get printed to screen too | ||
267 | niro | 2003 | rvecho ${sorted} |
268 | niro | 1248 | } |
269 | |||
270 | niro | 1639 | # message only echo | disabled in quiet mode |
271 | niro | 1248 | mecho() |
272 | { | ||
273 | local COLCYAN="\033[1;36m" | ||
274 | local COLDEFAULT="\033[0m" | ||
275 | niro | 1264 | local opts |
276 | niro | 1308 | local webcrlf |
277 | niro | 1264 | |
278 | niro | 1639 | # print nothing if quiet mode was requested |
279 | [[ ${QUIET} = true ]] && return | ||
280 | |||
281 | niro | 1248 | if [[ ${NOCOLORS} = true ]] |
282 | then | ||
283 | COLCYAN="" | ||
284 | COLDEFAULT="" | ||
285 | fi | ||
286 | |||
287 | niro | 1308 | [[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
288 | |||
289 | niro | 1264 | # respect -n |
290 | case $1 in | ||
291 | -n) shift; opts="n" ;; | ||
292 | esac | ||
293 | |||
294 | niro | 1308 | echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}" |
295 | niro | 1248 | } |
296 | niro | 1264 | |
297 | niro | 1639 | # prints error messages | enabled even in quiet mode |
298 | niro | 1264 | eecho() |
299 | { | ||
300 | local COLRED="\033[1;31m" | ||
301 | local COLDEFAULT="\033[0m" | ||
302 | local opts | ||
303 | niro | 1308 | local webcrlf |
304 | niro | 1264 | |
305 | if [[ ${NOCOLORS} = true ]] | ||
306 | then | ||
307 | COLRED="" | ||
308 | COLDEFAULT="" | ||
309 | fi | ||
310 | |||
311 | niro | 1308 | [[ ${WEBCRLF} = true ]] && webcrlf="<br>" |
312 | |||
313 | niro | 1264 | # respect -n |
314 | case $1 in | ||
315 | -n) shift; opts="n" ;; | ||
316 | esac | ||
317 | |||
318 | niro | 1308 | echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}" |
319 | niro | 1264 | } |
320 | |||
321 | niro | 1639 | # prints return values of get | enabled even in quiet mode |
322 | rvecho() | ||
323 | { | ||
324 | local COLPURPLE="\033[1;35m" | ||
325 | local COLDEFAULT="\033[0m" | ||
326 | local opts | ||
327 | local webcrlf | ||
328 | |||
329 | if [[ ${NOCOLORS} = true ]] | ||
330 | then | ||
331 | COLPURPLE="" | ||
332 | COLDEFAULT="" | ||
333 | fi | ||
334 | |||
335 | [[ ${WEBCRLF} = true ]] && webcrlf="<br>" | ||
336 | |||
337 | # respect -n | ||
338 | case $1 in | ||
339 | -n) shift; opts="n" ;; | ||
340 | esac | ||
341 | |||
342 | echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}" | ||
343 | } | ||
344 | |||
345 | # prints debug messages if requested | enabled even in quiet mode | ||
346 | decho() | ||
347 | { | ||
348 | # print nothing if debug mode was *not* requested | ||
349 | [[ ${DEBUG} != 1 ]] && return | ||
350 | |||
351 | eecho "DEBUG: ${@}" | ||
352 | } | ||
353 | |||
354 | niro | 1264 | path_not_empty() |
355 | { | ||
356 | local path="$1" | ||
357 | niro | 1639 | [[ -z ${path} ]] && eecho "path_not_empty(): no path given!" && return 1 |
358 | niro | 1264 | |
359 | # return ERR if path does not exist | ||
360 | [[ ! -d ${path} ]] && return 1 | ||
361 | # return ERR if path empty | ||
362 | [[ -z $(find "${path}" -mindepth 1 -maxdepth 1) ]] && return 1 | ||
363 | |||
364 | # every thing went ok, directory not empty | ||
365 | return 0 | ||
366 | } |