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

mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class revision 1330 by niro, Wed Feb 16 18:24:35 2011 UTC mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in revision 2271 by niro, Tue Jan 14 10:50:06 2014 UTC
# Line 1  Line 1 
1  # $Id$  # $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  # # import_resource $table $serial $resource $value
38  # import_resource()  # import_resource()
39  # {  # {
# Line 20  Line 54 
54  # run_class $method $caller $argv1 $argv2 ... $argvN  # run_class $method $caller $argv1 $argv2 ... $argvN
55  run_class()  run_class()
56  {  {
57   local method="$1"   local method="${GLOBAL_ARGV[0]}"
58   local caller="$2"   local caller="${GLOBAL_ARGV[1]}"
59   local class   local class
60   local cmd   local cmd
61   local argv   local i
62     local count
63    
64   if valid_session   if valid_session
65   then   then
66   class="${caller%.*}"   class="${caller%.*}"
67   cmd="${caller#*.}"   cmd="${caller#*.}"
  argv="${@/${caller}/}" # remove caller  
  argv="${argv/${method}/}" # remove method  
68    
69  # echo "method=${method}"   # copy GLOBAL_ARGV to CLASS_ARGV array without method and caller.class
70  # echo "caller=${caller}"   unset CLASS_ARGV
71  # echo "class=${class}"   count="${#GLOBAL_ARGV[*]}"
72  # echo "cmd=${cmd}"   for (( i=2; i<count; i++ ))
73  # echo "argv=${argv}"   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   # check if class.cmd exist
84   if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]]   if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]]
85   then   then
86   "${method}"_"${class}"_"${cmd}" ${argv}   "${method}"_"${class}"_"${cmd}"
87   else   else
88   echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'"   eecho "unknown method '${method}' . class '${class}' . cmd '${cmd}'"
89   fi   fi
90   else   else
91   invalid_session   invalid_session
# Line 58  help_topics() Line 99  help_topics()
99    
100   topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort)   topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort)
101   mecho "Global commands:"   mecho "Global commands:"
102   mecho "\timport  - import settings to database"   mecho "\timport   - import settings to database"
103   mecho "\tget     - shows current value for a settings"   mecho "\tget      - shows current value for a settings"
104   mecho "\tset     - sets value for a setting"   mecho "\tset      - sets value for a setting"
105   mecho "\tauth    - authenticate to the daemon"   mecho "\tauth     - authenticate to the daemon"
106   mecho "\tprovide - shows provides of a system"   mecho "\tprovide  - shows provides of a system"
107   mecho "\trequire - verify plugin requirements"   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"   mecho "\tnocolors - disable colors, useful for the webclient"
112   mecho "\thelp    - shows help"   mecho "\tcolors   - enable colors"
113   mecho "\tquit    - quits the connection to the server"   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   mecho
118   mecho "Help topics:"   mecho "Help topics:"
119   for i in ${topics}   for i in ${topics}
# Line 82  help_topics() Line 129  help_topics()
129   mecho "Type 'help [topic]' for more information about every topic."   mecho "Type 'help [topic]' for more information about every topic."
130  }  }
131    
 # on newer xorg-servers root is not allowed to run progs in a user session  
 x11runas()  
 {  
  su - "${MCORE_UNPRIV_USER}" -c "DISPLAY=${MCORE_XORG_DISPLAY} $@"  
 }  
   
 addconfig()  
 {  
  local opts  
   
  if [[ -z ${CONFIG} ]]  
  then  
  echo "You must define \$CONFIG varibale first!"  
  return 1  
  fi  
   
  if [[ ! -d $(dirname ${CONFIG}) ]]  
  then  
  install -d $(dirname ${CONFIG})  
  fi  
   
  # check for opts  
  case $1 in  
  -n) shift; opts=" -n" ;;  
  -e) shift; opts=" -e" ;;  
  esac  
   
  echo ${opts} "$@" >> ${CONFIG}  
 }  
   
 clearconfig()  
 {  
  if [[ -z ${CONFIG} ]]  
  then  
  echo "You must define \$CONFIG varibale first!"  
  return 1  
  fi  
   
  if [[ ! -d $(dirname ${CONFIG}) ]]  
  then  
  install -d $(dirname ${CONFIG})  
  fi  
  : > ${CONFIG}  
 }  
   
 # no_duplicate $list $item  
 no_duplicate()  
 {  
  local i  
  local list="$1"  
  local item="$2"  
   
  for i in ${list}  
  do  
  [[ ${i} = ${item} ]] && return 1  
  done  
   
  return 0  
 }  
   
132  require()  require()
133  {  {
134   local requires="$@"   local requires="$@"
# Line 154  require() Line 141  require()
141   then   then
142   export REQUIRE="${REQUIRE} ${i}"   export REQUIRE="${REQUIRE} ${i}"
143   else   else
144   [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!"   decho "duplicate provide '${i}' detected!"
145   fi   fi
146   done   done
147  }  }
# Line 183  verify_requirements() Line 170  verify_requirements()
170   # show missing and set the right retval   # show missing and set the right retval
171   if [[ -z ${missing} ]]   if [[ -z ${missing} ]]
172   then   then
173   mecho "${sorted}"   # do not escape, or CRLFS get printed to screen too
174     rvecho ${sorted}
175   return 0   return 0
176   else   else
177   for req in ${sorted}   for req in ${sorted}
# Line 191  verify_requirements() Line 179  verify_requirements()
179   if no_duplicate "${missing}" "$req"   if no_duplicate "${missing}" "$req"
180   then   then
181   # print normal   # print normal
182   mecho -n " ${req}"   rvecho -n "${req} "
183   else   else
184   # print missing   # print missing
185   eecho -n " ${req}"   eecho -n "${req} "
186   fi   fi
187   done   done
188     # print CRLF
189     echo
190   return 1   return 1
191   fi   fi
192  }  }
# Line 213  provide() Line 203  provide()
203   then   then
204   export PROVIDE="${PROVIDE} ${i}"   export PROVIDE="${PROVIDE} ${i}"
205   else   else
206   [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!"   decho "duplicate provide '${i}' detected!"
207   fi   fi
208   done   done
209  }  }
# Line 225  print_provide() Line 215  print_provide()
215   # sort them alpabetically   # sort them alpabetically
216   sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort)   sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort)
217   # do not escape, or CRLFS get printed to screen too   # do not escape, or CRLFS get printed to screen too
218   mecho ${sorted}   rvecho ${sorted}
219  }  }
220    
221  mecho()  help_daemon_mroot()
222  {  {
223   local COLCYAN="\033[1;36m"   mecho "get daemon.mroot"
224   local COLDEFAULT="\033[0m"   mecho " Prints current MROOT variable."
225   local opts   mecho
226   local webcrlf   mecho "set daemon.mroot [path]"
227     mecho " set MROOT variable to given path."
228   if [[ ${NOCOLORS} = true ]]  }
  then  
  COLCYAN=""  
  COLDEFAULT=""  
  fi  
   
  [[ ${WEBCRLF} = true ]] && webcrlf="<br>"  
   
  # respect -n  
  case $1 in  
  -n) shift; opts="n" ;;  
  esac  
229    
230   echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}"  get_daemon_mroot()
231    {
232     rvecho "${MROOT}"
233  }  }
234    
235  eecho()  set_daemon_mroot()
236  {  {
237   local COLRED="\033[1;31m"   local path=$1
  local COLDEFAULT="\033[0m"  
  local opts  
  local webcrlf  
238    
239   if [[ ${NOCOLORS} = true ]]   if [[ -d ${path} ]]
240   then   then
241   COLRED=""   export MROOT="${path}"
242   COLDEFAULT=""   decho "MROOT='${MROOT}' is set."
243     else
244     eecho "Path '${path}' does not exist. MROOT not set."
245   fi   fi
   
  [[ ${WEBCRLF} = true ]] && webcrlf="<br>"  
   
  # respect -n  
  case $1 in  
  -n) shift; opts="n" ;;  
  esac  
   
  echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}"  
246  }  }
247    
248  path_not_empty()  print_version()
249  {  {
250   local path="$1"   echo "mcored-$(<${MCORE_LIBDIR}/VERSION)"
  [[ -z ${path} ]] && "path_not_empty(): no path given!" && return 1  
   
  # return ERR if path does not exist  
  [[ ! -d ${path} ]] && return 1  
  # return ERR if path empty  
  [[ -z $(find "${path}" -mindepth 1 -maxdepth 1) ]] && return 1  
   
  # every thing went ok, directory not empty  
  return 0  
251  }  }

Legend:
Removed from v.1330  
changed lines
  Added in v.2271