Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2269 - (hide annotations) (download)
Tue Jan 14 10:34:57 2014 UTC (10 years, 3 months ago) by niro
File size: 4924 byte(s)
-use global argv arrays GLOBAL_ARGV and CLASS_ARGV to fix whitespace issues with the read cmd. escaping works with this now. every class must use the CLASS_ARGV array for arguments
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 niro 2258 include ${i} || eecho "error loading ${i}"
12 niro 1915 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 niro 2269 local method="${GLOBAL_ARGV[0]"
58     local caller="${GLOBAL_ARGV[1]"
59 niro 1248 local class
60     local cmd
61 niro 2269 local i
62     local count
63 niro 1248
64 niro 1308 if valid_session
65 niro 1248 then
66     class="${caller%.*}"
67     cmd="${caller#*.}"
68    
69 niro 2269 # 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 niro 1248
77 niro 2269 # 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 niro 1248 # check if class.cmd exist
84     if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]]
85     then
86 niro 2269 "${method}"_"${class}"_"${cmd}"
87 niro 1248 else
88 niro 2243 eecho "unknown method '${method}' . class '${class}' . cmd '${cmd}'"
89 niro 1248 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 niro 1350 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 niro 1925 mecho "\treload - reloads all client classes plugins"
109     mecho "\trestart - restarts the daemon"
110 niro 2005 mecho "\tstop - stops the daemon"
111 niro 1330 mecho "\tnocolors - disable colors, useful for the webclient"
112 niro 2006 mecho "\tcolors - enable colors"
113 niro 1639 mecho "\tquiet - do not print any unecessary messages"
114 niro 1350 mecho "\thelp - shows help"
115 niro 2044 mecho "\tversion - prints version of the daemon"
116 niro 1350 mecho "\tquit - quits the connection to the server"
117 niro 1248 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 niro 1264 mecho
129     mecho "Type 'help [topic]' for more information about every topic."
130 niro 1248 }
131    
132     require()
133     {
134     local requires="$@"
135     local i
136    
137     for i in ${requires}
138     do
139 niro 1264 # check for duplicate provides
140     if no_duplicate "${PROVIDE}" "${i}"
141     then
142     export REQUIRE="${REQUIRE} ${i}"
143     else
144 niro 1639 decho "duplicate provide '${i}' detected!"
145 niro 1264 fi
146 niro 1248 done
147     }
148    
149 niro 1264 verify_requirements()
150 niro 1248 {
151 niro 1264 local req
152     local prov
153     local missing
154     local sorted
155 niro 1248
156 niro 1264 for req in ${REQUIRE}
157 niro 1248 do
158 niro 1264 # 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 niro 1248 done
166    
167 niro 1264 # 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 niro 2115 # do not escape, or CRLFS get printed to screen too
174     rvecho ${sorted}
175 niro 1264 return 0
176     else
177     for req in ${sorted}
178     do
179     if no_duplicate "${missing}" "$req"
180     then
181     # print normal
182 niro 2115 rvecho -n "${req} "
183 niro 1264 else
184     # print missing
185 niro 2115 eecho -n "${req} "
186 niro 1264 fi
187     done
188 niro 2115 # print CRLF
189     echo
190 niro 1264 return 1
191     fi
192 niro 1248 }
193    
194     provide()
195     {
196     local provides="$@"
197     local i
198    
199     for i in ${provides}
200     do
201     # check for duplicate provides
202 niro 1264 if no_duplicate "${PROVIDE}" "${i}"
203 niro 1248 then
204     export PROVIDE="${PROVIDE} ${i}"
205     else
206 niro 1639 decho "duplicate provide '${i}' detected!"
207 niro 1248 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 niro 2003 rvecho ${sorted}
219 niro 1248 }
220    
221 niro 2007 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 niro 2008
248 niro 2052 print_version()
249     {
250 niro 2139 echo "mcored-$(<${MCORE_LIBDIR}/VERSION)"
251 niro 2052 }