Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2302 - (hide 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 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 niro 2302 kill -SIGTERM ${pid}
32 niro 2005 done
33     }
34    
35 niro 1252 # # 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 niro 1248
52     # run_class $method $caller $argv1 $argv2 ... $argvN
53     run_class()
54     {
55 niro 2271 local method="${GLOBAL_ARGV[0]}"
56     local caller="${GLOBAL_ARGV[1]}"
57 niro 1248 local class
58     local cmd
59 niro 2269 local i
60     local count
61 niro 1248
62 niro 1308 if valid_session
63 niro 1248 then
64     class="${caller%.*}"
65     cmd="${caller#*.}"
66    
67 niro 2269 # 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 niro 1248
75 niro 2269 # 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 niro 1248 # check if class.cmd exist
82     if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]]
83     then
84 niro 2269 "${method}"_"${class}"_"${cmd}"
85 niro 1248 else
86 niro 2243 eecho "unknown method '${method}' . class '${class}' . cmd '${cmd}'"
87 niro 1248 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 niro 1350 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 niro 1925 mecho "\treload - reloads all client classes plugins"
107     mecho "\trestart - restarts the daemon"
108 niro 2005 mecho "\tstop - stops the daemon"
109 niro 1330 mecho "\tnocolors - disable colors, useful for the webclient"
110 niro 2006 mecho "\tcolors - enable colors"
111 niro 1639 mecho "\tquiet - do not print any unecessary messages"
112 niro 1350 mecho "\thelp - shows help"
113 niro 2044 mecho "\tversion - prints version of the daemon"
114 niro 1350 mecho "\tquit - quits the connection to the server"
115 niro 1248 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 niro 1264 mecho
127     mecho "Type 'help [topic]' for more information about every topic."
128 niro 1248 }
129    
130     require()
131     {
132     local requires="$@"
133     local i
134    
135     for i in ${requires}
136     do
137 niro 1264 # check for duplicate provides
138     if no_duplicate "${PROVIDE}" "${i}"
139     then
140     export REQUIRE="${REQUIRE} ${i}"
141     else
142 niro 1639 decho "duplicate provide '${i}' detected!"
143 niro 1264 fi
144 niro 1248 done
145     }
146    
147 niro 1264 verify_requirements()
148 niro 1248 {
149 niro 1264 local req
150     local prov
151     local missing
152     local sorted
153 niro 1248
154 niro 1264 for req in ${REQUIRE}
155 niro 1248 do
156 niro 1264 # 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 niro 1248 done
164    
165 niro 1264 # 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 niro 2115 # do not escape, or CRLFS get printed to screen too
172     rvecho ${sorted}
173 niro 1264 return 0
174     else
175     for req in ${sorted}
176     do
177     if no_duplicate "${missing}" "$req"
178     then
179     # print normal
180 niro 2115 rvecho -n "${req} "
181 niro 1264 else
182     # print missing
183 niro 2115 eecho -n "${req} "
184 niro 1264 fi
185     done
186 niro 2115 # print CRLF
187     echo
188 niro 1264 return 1
189     fi
190 niro 1248 }
191    
192     provide()
193     {
194     local provides="$@"
195     local i
196    
197     for i in ${provides}
198     do
199     # check for duplicate provides
200 niro 1264 if no_duplicate "${PROVIDE}" "${i}"
201 niro 1248 then
202     export PROVIDE="${PROVIDE} ${i}"
203     else
204 niro 1639 decho "duplicate provide '${i}' detected!"
205 niro 1248 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 niro 2003 rvecho ${sorted}
217 niro 1248 }
218    
219 niro 2007 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 niro 2008
246 niro 2052 print_version()
247     {
248 niro 2139 echo "mcored-$(<${MCORE_LIBDIR}/VERSION)"
249 niro 2052 }