Annotation of /mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in
Parent Directory | Revision Log
Revision 2228 -
(hide annotations)
(download)
Fri Jan 10 23:51:35 2014 UTC (10 years, 8 months ago) by niro
File size: 4719 byte(s)
Fri Jan 10 23:51:35 2014 UTC (10 years, 8 months ago) by niro
File size: 4719 byte(s)
-renamed daemon.global.class -> daemon.global.class.in
1 | niro | 1248 | # $Id$ |
2 | |||
3 | niro | 2139 | # loads client classes from $MCORE_LIBDIR |
4 | niro | 1915 | load_client_classes() |
5 | { | ||
6 | niro | 2030 | local i |
7 | |||
8 | niro | 1915 | # client specific |
9 | niro | 2139 | for i in $(find ${MCORE_LIBDIR}/include -type f -name \*.client.class) |
10 | niro | 1915 | 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 | niro | 2005 | # 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 | niro | 1252 | # # 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 | niro | 1248 | |
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 | niro | 1308 | if valid_session |
64 | niro | 1248 | 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 | niro | 1639 | eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'" |
82 | niro | 1248 | 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 | niro | 1350 | 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 | niro | 1925 | mecho "\treload - reloads all client classes plugins" |
102 | mecho "\trestart - restarts the daemon" | ||
103 | niro | 2005 | mecho "\tstop - stops the daemon" |
104 | niro | 1330 | mecho "\tnocolors - disable colors, useful for the webclient" |
105 | niro | 2006 | mecho "\tcolors - enable colors" |
106 | niro | 1639 | mecho "\tquiet - do not print any unecessary messages" |
107 | niro | 1350 | mecho "\thelp - shows help" |
108 | niro | 2044 | mecho "\tversion - prints version of the daemon" |
109 | niro | 1350 | mecho "\tquit - quits the connection to the server" |
110 | niro | 1248 | 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 | niro | 1264 | mecho |
122 | mecho "Type 'help [topic]' for more information about every topic." | ||
123 | niro | 1248 | } |
124 | |||
125 | require() | ||
126 | { | ||
127 | local requires="$@" | ||
128 | local i | ||
129 | |||
130 | for i in ${requires} | ||
131 | do | ||
132 | niro | 1264 | # check for duplicate provides |
133 | if no_duplicate "${PROVIDE}" "${i}" | ||
134 | then | ||
135 | export REQUIRE="${REQUIRE} ${i}" | ||
136 | else | ||
137 | niro | 1639 | decho "duplicate provide '${i}' detected!" |
138 | niro | 1264 | fi |
139 | niro | 1248 | done |
140 | } | ||
141 | |||
142 | niro | 1264 | verify_requirements() |
143 | niro | 1248 | { |
144 | niro | 1264 | local req |
145 | local prov | ||
146 | local missing | ||
147 | local sorted | ||
148 | niro | 1248 | |
149 | niro | 1264 | for req in ${REQUIRE} |
150 | niro | 1248 | do |
151 | niro | 1264 | # 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 | niro | 1248 | done |
159 | |||
160 | niro | 1264 | # 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 | niro | 2115 | # do not escape, or CRLFS get printed to screen too |
167 | rvecho ${sorted} | ||
168 | niro | 1264 | return 0 |
169 | else | ||
170 | for req in ${sorted} | ||
171 | do | ||
172 | if no_duplicate "${missing}" "$req" | ||
173 | then | ||
174 | # print normal | ||
175 | niro | 2115 | rvecho -n "${req} " |
176 | niro | 1264 | else |
177 | # print missing | ||
178 | niro | 2115 | eecho -n "${req} " |
179 | niro | 1264 | fi |
180 | done | ||
181 | niro | 2115 | # print CRLF |
182 | echo | ||
183 | niro | 1264 | return 1 |
184 | fi | ||
185 | niro | 1248 | } |
186 | |||
187 | provide() | ||
188 | { | ||
189 | local provides="$@" | ||
190 | local i | ||
191 | |||
192 | for i in ${provides} | ||
193 | do | ||
194 | # check for duplicate provides | ||
195 | niro | 1264 | if no_duplicate "${PROVIDE}" "${i}" |
196 | niro | 1248 | then |
197 | export PROVIDE="${PROVIDE} ${i}" | ||
198 | else | ||
199 | niro | 1639 | decho "duplicate provide '${i}' detected!" |
200 | niro | 1248 | 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 | niro | 2003 | rvecho ${sorted} |
212 | niro | 1248 | } |
213 | |||
214 | niro | 2007 | 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 | niro | 2008 | |
241 | niro | 2052 | print_version() |
242 | { | ||
243 | niro | 2139 | echo "mcored-$(<${MCORE_LIBDIR}/VERSION)" |
244 | niro | 2052 | } |