Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1248 by niro, Wed Feb 2 20:20:24 2011 UTC revision 2140 by niro, Fri Jan 10 12:02:07 2014 UTC
# Line 1  Line 1 
1  # $Id$  # $Id$
2    
3  # import_resource $table $serial $resource $value  # loads client classes from $MCORE_LIBDIR
4  import_resource()  load_client_classes()
5  {  {
6   local table="$1"   local i
  local serial="$2"  
  local resource="$3"  
  local value="$4"  
7    
8   if [[ ${DEBUG} = 1 ]]   # client specific
9   then   for i in $(find ${MCORE_LIBDIR}/include -type f -name \*.client.class)
10   echo "${table}->${resource}=${value}" >> /root/lala.log   do
11   echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log   source ${i} || eecho "error loading ${i}"
12   fi   done
13    }
14    
15   mysql_insert "${table}",serial="${serial}","${resource}"="${value}"  # 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  # run_class $method $caller $argv1 $argv2 ... $argvN
55  run_class()  run_class()
56  {  {
# Line 26  run_class() Line 60  run_class()
60   local cmd   local cmd
61   local argv   local argv
62    
63   if validate_session   if valid_session
64   then   then
65   class="${caller%.*}"   class="${caller%.*}"
66   cmd="${caller#*.}"   cmd="${caller#*.}"
# Line 44  run_class() Line 78  run_class()
78   then   then
79   "${method}"_"${class}"_"${cmd}" ${argv}   "${method}"_"${class}"_"${cmd}" ${argv}
80   else   else
81   echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'"   eecho "unkown method '${method}' . class '${class}' . cmd '${cmd}'"
82   fi   fi
83   else   else
84   invalid_session   invalid_session
# Line 58  help_topics() Line 92  help_topics()
92    
93   topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort)   topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort)
94   mecho "Global commands:"   mecho "Global commands:"
95   mecho "\timport  - import settings to database"   mecho "\timport   - import settings to database"
96   mecho "\tget     - shows current value for a settings"   mecho "\tget      - shows current value for a settings"
97   mecho "\tset     - sets value for a setting"   mecho "\tset      - sets value for a setting"
98   mecho "\tauth    - authenticate to the daemon"   mecho "\tauth     - authenticate to the daemon"
99   mecho "\tprovide - shows provides of a system"   mecho "\tprovide  - shows provides of a system"
100   mecho "\thelp    - shows help"   mecho "\trequire  - verify plugin requirements"
101     mecho "\treload   - reloads all client classes plugins"
102     mecho "\trestart  - restarts the daemon"
103     mecho "\tstop     - stops the daemon"
104     mecho "\tnocolors - disable colors, useful for the webclient"
105     mecho "\tcolors   - enable colors"
106     mecho "\tquiet    - do not print any unecessary messages"
107     mecho "\thelp     - shows help"
108     mecho "\tversion  - prints version of the daemon"
109     mecho "\tquit     - quits the connection to the server"
110   mecho   mecho
111   mecho "Help topics:"   mecho "Help topics:"
112   for i in ${topics}   for i in ${topics}
# Line 75  help_topics() Line 118  help_topics()
118    
119   mecho "\t${i}"   mecho "\t${i}"
120   done   done
121  }   mecho
122     mecho "Type 'help [topic]' for more information about every topic."
 # on newer xorg-servers root is not allowed to run progs in a user session  
 x11runas()  
 {  
  su - "${MCORE_UNPRIV_USER}" -c "$@"  
 }  
   
 addconfig()  
 {  
  if [[ -z ${CONFIG} ]]  
  then  
  echo "You must define \$CONFIG varibale first!"  
  return 1  
  fi  
   
  if [[ ! -d $(dirname ${CONFIG}) ]]  
  then  
  install -d $(dirname ${CONFIG})  
  fi  
  echo "$@" >> ${CONFIG}  
 }  
   
 clearconfig()  
 {  
  if [[ -z ${CONFIG} ]]  
  then  
  echo "You must define \$CONFIG varibale first!"  
  return 1  
  fi  
   
  : > ${CONFIG}  
123  }  }
124    
125  require()  require()
# Line 116  require() Line 129  require()
129    
130   for i in ${requires}   for i in ${requires}
131   do   do
132   export REQUIRE="${REQUIRE} ${i}"   # check for duplicate provides
133     if no_duplicate "${PROVIDE}" "${i}"
134     then
135     export REQUIRE="${REQUIRE} ${i}"
136     else
137     decho "duplicate provide '${i}' detected!"
138     fi
139   done   done
140  }  }
141    
142  not_provided()  verify_requirements()
143  {  {
144   local i   local req
145   local item="$1"   local prov
146     local missing
147     local sorted
148    
149   for i in ${PROVIDE}   for req in ${REQUIRE}
150   do   do
151   [[ ${i} = ${item} ]] && return 1   # 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   done   done
159    
160   return 0   # 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     # do not escape, or CRLFS get printed to screen too
167     rvecho ${sorted}
168     return 0
169     else
170     for req in ${sorted}
171     do
172     if no_duplicate "${missing}" "$req"
173     then
174     # print normal
175     rvecho -n "${req} "
176     else
177     # print missing
178     eecho -n "${req} "
179     fi
180     done
181     # print CRLF
182     echo
183     return 1
184     fi
185  }  }
186    
187  provide()  provide()
# Line 141  provide() Line 192  provide()
192   for i in ${provides}   for i in ${provides}
193   do   do
194   # check for duplicate provides   # check for duplicate provides
195   if not_provided "${i}"   if no_duplicate "${PROVIDE}" "${i}"
196   then   then
197   export PROVIDE="${PROVIDE} ${i}"   export PROVIDE="${PROVIDE} ${i}"
198   else   else
199   [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!"   decho "duplicate provide '${i}' detected!"
200   fi   fi
201   done   done
202  }  }
# Line 157  print_provide() Line 208  print_provide()
208   # sort them alpabetically   # sort them alpabetically
209   sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort)   sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort)
210   # do not escape, or CRLFS get printed to screen too   # do not escape, or CRLFS get printed to screen too
211   mecho ${sorted}   rvecho ${sorted}
212    }
213    
214    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  mecho()  get_daemon_mroot()
224  {  {
225   local COLCYAN="\033[1;36m"   rvecho "${MROOT}"
226   local COLDEFAULT="\033[0m"  }
227   if [[ ${NOCOLORS} = true ]]  
228    set_daemon_mroot()
229    {
230     local path=$1
231    
232     if [[ -d ${path} ]]
233   then   then
234   COLCYAN=""   export MROOT="${path}"
235   COLDEFAULT=""   decho "MROOT='${MROOT}' is set."
236     else
237     eecho "Path '${path}' does not exist. MROOT not set."
238   fi   fi
239    }
240    
241   echo -e "${COLCYAN}$@${COLDEFAULT}"  print_version()
242    {
243     echo "mcored-$(<${MCORE_LIBDIR}/VERSION)"
244  }  }

Legend:
Removed from v.1248  
changed lines
  Added in v.2140