Contents of /mcore-src/trunk/mcore-tools/src/include/daemon.global.class
Parent Directory | Revision Log
Revision 2207 -
(show annotations)
(download)
Fri Jan 10 14:57:04 2014 UTC (10 years, 8 months ago) by niro
File size: 4719 byte(s)
Fri Jan 10 14:57:04 2014 UTC (10 years, 8 months ago) by niro
File size: 4719 byte(s)
-moved daemon/include to src/include
1 | # $Id$ |
2 | |
3 | # loads client classes from $MCORE_LIBDIR |
4 | load_client_classes() |
5 | { |
6 | local i |
7 | |
8 | # client specific |
9 | for i in $(find ${MCORE_LIBDIR}/include -type f -name \*.client.class) |
10 | do |
11 | source ${i} || eecho "error loading ${i}" |
12 | done |
13 | } |
14 | |
15 | # restarts the whole service via remote cmd |
16 | restart_service() |
17 | { |
18 | local pid |
19 | for pid in $(pidof sslsvd) |
20 | do |
21 | kill -SIGHUP ${pid} |
22 | done |
23 | } |
24 | |
25 | # stops the whole service via remote cmd |
26 | stop_service() |
27 | { |
28 | local pid |
29 | for pid in $(pidof sslsvd) |
30 | do |
31 | kill -15 ${pid} |
32 | sleep 1 |
33 | kill -9 ${pid} |
34 | done |
35 | } |
36 | |
37 | # # import_resource $table $serial $resource $value |
38 | # import_resource() |
39 | # { |
40 | # local table="$1" |
41 | # local serial="$2" |
42 | # local resource="$3" |
43 | # local value="$4" |
44 | # |
45 | # if [[ ${DEBUG} = 1 ]] |
46 | # then |
47 | # echo "${table}->${resource}=${value}" >> /root/lala.log |
48 | # echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log |
49 | # fi |
50 | # |
51 | # mysql_insert "${table}",serial="${serial}","${resource}"="${value}" |
52 | # } |
53 | |
54 | # run_class $method $caller $argv1 $argv2 ... $argvN |
55 | run_class() |
56 | { |
57 | local method="$1" |
58 | local caller="$2" |
59 | local class |
60 | local cmd |
61 | local argv |
62 | |
63 | if valid_session |
64 | then |
65 | class="${caller%.*}" |
66 | cmd="${caller#*.}" |
67 | argv="${@/${caller}/}" # remove caller |
68 | argv="${argv/${method}/}" # remove method |
69 | |
70 | # echo "method=${method}" |
71 | # echo "caller=${caller}" |
72 | # echo "class=${class}" |
73 | # echo "cmd=${cmd}" |
74 | # echo "argv=${argv}" |
75 | |
76 | # check if class.cmd exist |
77 | if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]] |
78 | then |
79 | "${method}"_"${class}"_"${cmd}" ${argv} |
80 | else |
81 | eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'" |
82 | fi |
83 | else |
84 | invalid_session |
85 | fi |
86 | } |
87 | |
88 | help_topics() |
89 | { |
90 | local i |
91 | local topics |
92 | |
93 | topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) |
94 | mecho "Global commands:" |
95 | mecho "\timport - import settings to database" |
96 | mecho "\tget - shows current value for a settings" |
97 | mecho "\tset - sets value for a setting" |
98 | mecho "\tauth - authenticate to the daemon" |
99 | mecho "\tprovide - shows provides of a system" |
100 | mecho "\trequire - verify plugin requirements" |
101 | mecho "\treload - reloads all client classes plugins" |
102 | mecho "\trestart - restarts the daemon" |
103 | mecho "\tstop - stops the daemon" |
104 | mecho "\tnocolors - disable colors, useful for the webclient" |
105 | mecho "\tcolors - enable colors" |
106 | mecho "\tquiet - do not print any unecessary messages" |
107 | mecho "\thelp - shows help" |
108 | mecho "\tversion - prints version of the daemon" |
109 | mecho "\tquit - quits the connection to the server" |
110 | mecho |
111 | mecho "Help topics:" |
112 | for i in ${topics} |
113 | do |
114 | # excludes |
115 | case ${i} in |
116 | help_topics|topics) continue ;; |
117 | esac |
118 | |
119 | mecho "\t${i}" |
120 | done |
121 | mecho |
122 | mecho "Type 'help [topic]' for more information about every topic." |
123 | } |
124 | |
125 | require() |
126 | { |
127 | local requires="$@" |
128 | local i |
129 | |
130 | for i in ${requires} |
131 | do |
132 | # check for duplicate provides |
133 | if no_duplicate "${PROVIDE}" "${i}" |
134 | then |
135 | export REQUIRE="${REQUIRE} ${i}" |
136 | else |
137 | decho "duplicate provide '${i}' detected!" |
138 | fi |
139 | done |
140 | } |
141 | |
142 | verify_requirements() |
143 | { |
144 | local req |
145 | local prov |
146 | local missing |
147 | local sorted |
148 | |
149 | for req in ${REQUIRE} |
150 | do |
151 | # scan PROVIDE for dupes |
152 | # if a dupe is found, then requirement is fullfilled |
153 | # else add to missing |
154 | if no_duplicate "${PROVIDE}" "${req}" |
155 | then |
156 | missing="${missing} ${req}" |
157 | fi |
158 | done |
159 | |
160 | # sort them alpabetically |
161 | sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort) |
162 | |
163 | # show missing and set the right retval |
164 | if [[ -z ${missing} ]] |
165 | then |
166 | # do not escape, or CRLFS get printed to screen too |
167 | rvecho ${sorted} |
168 | return 0 |
169 | else |
170 | for req in ${sorted} |
171 | do |
172 | if no_duplicate "${missing}" "$req" |
173 | then |
174 | # print normal |
175 | rvecho -n "${req} " |
176 | else |
177 | # print missing |
178 | eecho -n "${req} " |
179 | fi |
180 | done |
181 | # print CRLF |
182 | echo |
183 | return 1 |
184 | fi |
185 | } |
186 | |
187 | provide() |
188 | { |
189 | local provides="$@" |
190 | local i |
191 | |
192 | for i in ${provides} |
193 | do |
194 | # check for duplicate provides |
195 | if no_duplicate "${PROVIDE}" "${i}" |
196 | then |
197 | export PROVIDE="${PROVIDE} ${i}" |
198 | else |
199 | decho "duplicate provide '${i}' detected!" |
200 | fi |
201 | done |
202 | } |
203 | |
204 | print_provide() |
205 | { |
206 | local sorted |
207 | |
208 | # sort them alpabetically |
209 | sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) |
210 | # do not escape, or CRLFS get printed to screen too |
211 | rvecho ${sorted} |
212 | } |
213 | |
214 | help_daemon_mroot() |
215 | { |
216 | mecho "get daemon.mroot" |
217 | mecho " Prints current MROOT variable." |
218 | mecho |
219 | mecho "set daemon.mroot [path]" |
220 | mecho " set MROOT variable to given path." |
221 | } |
222 | |
223 | get_daemon_mroot() |
224 | { |
225 | rvecho "${MROOT}" |
226 | } |
227 | |
228 | set_daemon_mroot() |
229 | { |
230 | local path=$1 |
231 | |
232 | if [[ -d ${path} ]] |
233 | then |
234 | export MROOT="${path}" |
235 | decho "MROOT='${MROOT}' is set." |
236 | else |
237 | eecho "Path '${path}' does not exist. MROOT not set." |
238 | fi |
239 | } |
240 | |
241 | print_version() |
242 | { |
243 | echo "mcored-$(<${MCORE_LIBDIR}/VERSION)" |
244 | } |