Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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