Magellan Linux

Contents of /mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2271 - (show annotations) (download)
Tue Jan 14 10:50:06 2014 UTC (10 years, 3 months ago) by niro
File size: 4926 byte(s)
-fixed broken variables
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 include ${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="${GLOBAL_ARGV[0]}"
58 local caller="${GLOBAL_ARGV[1]}"
59 local class
60 local cmd
61 local i
62 local count
63
64 if valid_session
65 then
66 class="${caller%.*}"
67 cmd="${caller#*.}"
68
69 # copy GLOBAL_ARGV to CLASS_ARGV array without method and caller.class
70 unset CLASS_ARGV
71 count="${#GLOBAL_ARGV[*]}"
72 for (( i=2; i<count; i++ ))
73 do
74 CLASS_ARGV[${i}-2]="${GLOBAL_ARGV[${i}]}"
75 done
76
77 # decho "method=${method}"
78 # decho "caller=${caller}"
79 # decho "class=${class}"
80 # decho "cmd=${cmd}"
81 # decho "class argv=$(printf '\"%s\" ' ${CLASS_ARGV[*]}; printf '\n')"
82
83 # check if class.cmd exist
84 if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]]
85 then
86 "${method}"_"${class}"_"${cmd}"
87 else
88 eecho "unknown method '${method}' . class '${class}' . cmd '${cmd}'"
89 fi
90 else
91 invalid_session
92 fi
93 }
94
95 help_topics()
96 {
97 local i
98 local topics
99
100 topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort)
101 mecho "Global commands:"
102 mecho "\timport - import settings to database"
103 mecho "\tget - shows current value for a settings"
104 mecho "\tset - sets value for a setting"
105 mecho "\tauth - authenticate to the daemon"
106 mecho "\tprovide - shows provides of a system"
107 mecho "\trequire - verify plugin requirements"
108 mecho "\treload - reloads all client classes plugins"
109 mecho "\trestart - restarts the daemon"
110 mecho "\tstop - stops the daemon"
111 mecho "\tnocolors - disable colors, useful for the webclient"
112 mecho "\tcolors - enable colors"
113 mecho "\tquiet - do not print any unecessary messages"
114 mecho "\thelp - shows help"
115 mecho "\tversion - prints version of the daemon"
116 mecho "\tquit - quits the connection to the server"
117 mecho
118 mecho "Help topics:"
119 for i in ${topics}
120 do
121 # excludes
122 case ${i} in
123 help_topics|topics) continue ;;
124 esac
125
126 mecho "\t${i}"
127 done
128 mecho
129 mecho "Type 'help [topic]' for more information about every topic."
130 }
131
132 require()
133 {
134 local requires="$@"
135 local i
136
137 for i in ${requires}
138 do
139 # check for duplicate provides
140 if no_duplicate "${PROVIDE}" "${i}"
141 then
142 export REQUIRE="${REQUIRE} ${i}"
143 else
144 decho "duplicate provide '${i}' detected!"
145 fi
146 done
147 }
148
149 verify_requirements()
150 {
151 local req
152 local prov
153 local missing
154 local sorted
155
156 for req in ${REQUIRE}
157 do
158 # scan PROVIDE for dupes
159 # if a dupe is found, then requirement is fullfilled
160 # else add to missing
161 if no_duplicate "${PROVIDE}" "${req}"
162 then
163 missing="${missing} ${req}"
164 fi
165 done
166
167 # sort them alpabetically
168 sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort)
169
170 # show missing and set the right retval
171 if [[ -z ${missing} ]]
172 then
173 # do not escape, or CRLFS get printed to screen too
174 rvecho ${sorted}
175 return 0
176 else
177 for req in ${sorted}
178 do
179 if no_duplicate "${missing}" "$req"
180 then
181 # print normal
182 rvecho -n "${req} "
183 else
184 # print missing
185 eecho -n "${req} "
186 fi
187 done
188 # print CRLF
189 echo
190 return 1
191 fi
192 }
193
194 provide()
195 {
196 local provides="$@"
197 local i
198
199 for i in ${provides}
200 do
201 # check for duplicate provides
202 if no_duplicate "${PROVIDE}" "${i}"
203 then
204 export PROVIDE="${PROVIDE} ${i}"
205 else
206 decho "duplicate provide '${i}' detected!"
207 fi
208 done
209 }
210
211 print_provide()
212 {
213 local sorted
214
215 # sort them alpabetically
216 sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort)
217 # do not escape, or CRLFS get printed to screen too
218 rvecho ${sorted}
219 }
220
221 help_daemon_mroot()
222 {
223 mecho "get daemon.mroot"
224 mecho " Prints current MROOT variable."
225 mecho
226 mecho "set daemon.mroot [path]"
227 mecho " set MROOT variable to given path."
228 }
229
230 get_daemon_mroot()
231 {
232 rvecho "${MROOT}"
233 }
234
235 set_daemon_mroot()
236 {
237 local path=$1
238
239 if [[ -d ${path} ]]
240 then
241 export MROOT="${path}"
242 decho "MROOT='${MROOT}' is set."
243 else
244 eecho "Path '${path}' does not exist. MROOT not set."
245 fi
246 }
247
248 print_version()
249 {
250 echo "mcored-$(<${MCORE_LIBDIR}/VERSION)"
251 }