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 1350 by niro, Thu Feb 17 21:42:57 2011 UTC mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in revision 2258 by niro, Mon Jan 13 14:25:18 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 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 "unknown method '${method}' . class '${class}' . cmd '${cmd}'"
82   fi   fi
83   else   else
84   invalid_session   invalid_session
# Line 64  help_topics() Line 98  help_topics()
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 "\trequire  - verify plugin requirements"   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"   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"   mecho "\thelp     - shows help"
108     mecho "\tversion  - prints version of the daemon"
109   mecho "\tquit     - quits the connection to the server"   mecho "\tquit     - quits the connection to the server"
110   mecho   mecho
111   mecho "Help topics:"   mecho "Help topics:"
# Line 82  help_topics() Line 122  help_topics()
122   mecho "Type 'help [topic]' for more information about every topic."   mecho "Type 'help [topic]' for more information about every topic."
123  }  }
124    
 # 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  
 }  
   
125  require()  require()
126  {  {
127   local requires="$@"   local requires="$@"
# Line 154  require() Line 134  require()
134   then   then
135   export REQUIRE="${REQUIRE} ${i}"   export REQUIRE="${REQUIRE} ${i}"
136   else   else
137   [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!"   decho "duplicate provide '${i}' detected!"
138   fi   fi
139   done   done
140  }  }
# Line 183  verify_requirements() Line 163  verify_requirements()
163   # show missing and set the right retval   # show missing and set the right retval
164   if [[ -z ${missing} ]]   if [[ -z ${missing} ]]
165   then   then
166   mecho "${sorted}"   # do not escape, or CRLFS get printed to screen too
167     rvecho ${sorted}
168   return 0   return 0
169   else   else
170   for req in ${sorted}   for req in ${sorted}
# Line 191  verify_requirements() Line 172  verify_requirements()
172   if no_duplicate "${missing}" "$req"   if no_duplicate "${missing}" "$req"
173   then   then
174   # print normal   # print normal
175   mecho -n " ${req}"   rvecho -n "${req} "
176   else   else
177   # print missing   # print missing
178   eecho -n " ${req}"   eecho -n "${req} "
179   fi   fi
180   done   done
181     # print CRLF
182     echo
183   return 1   return 1
184   fi   fi
185  }  }
# Line 213  provide() Line 196  provide()
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 225  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  mecho()  help_daemon_mroot()
215  {  {
216   local COLCYAN="\033[1;36m"   mecho "get daemon.mroot"
217   local COLDEFAULT="\033[0m"   mecho " Prints current MROOT variable."
218   local opts   mecho
219   local webcrlf   mecho "set daemon.mroot [path]"
220     mecho " set MROOT variable to given path."
221   if [[ ${NOCOLORS} = true ]]  }
  then  
  COLCYAN=""  
  COLDEFAULT=""  
  fi  
   
  [[ ${WEBCRLF} = true ]] && webcrlf="<br>"  
   
  # respect -n  
  case $1 in  
  -n) shift; opts="n" ;;  
  esac  
222    
223   echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}"  get_daemon_mroot()
224    {
225     rvecho "${MROOT}"
226  }  }
227    
228  eecho()  set_daemon_mroot()
229  {  {
230   local COLRED="\033[1;31m"   local path=$1
  local COLDEFAULT="\033[0m"  
  local opts  
  local webcrlf  
231    
232   if [[ ${NOCOLORS} = true ]]   if [[ -d ${path} ]]
233   then   then
234   COLRED=""   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
   
  [[ ${WEBCRLF} = true ]] && webcrlf="<br>"  
   
  # respect -n  
  case $1 in  
  -n) shift; opts="n" ;;  
  esac  
   
  echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}"  
239  }  }
240    
241  path_not_empty()  print_version()
242  {  {
243   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  
244  }  }

Legend:
Removed from v.1350  
changed lines
  Added in v.2258