--- mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2012/08/13 09:32:23 2003 +++ mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in 2015/09/03 07:54:18 2426 @@ -1,12 +1,20 @@ # $Id$ -# loads client classes from $MCLIBDIR -load_client_classes() +# loads client classes from $MCORE_LIBDIR +load_classes() { + local class + local classtype + + case $1 in + client|control) classtype="$1" ;; + *) die "Unknown classes type '$1'" ;; + esac + # client specific - for i in ${MCLIBDIR}/include/*.client.class + for class in $(find ${MCORE_LIBDIR}/include -type f -name \*.${classtype}.class) do - source ${i} || eecho "error loading ${i}" + include ${class} || eecho "error loading ${class}" done } @@ -20,6 +28,16 @@ done } +# stops the whole service via remote cmd +stop_service() +{ + local pid + for pid in $(pidof sslsvd) + do + kill -SIGTERM ${pid} + done +} + # # import_resource $table $serial $resource $value # import_resource() # { @@ -40,31 +58,38 @@ # run_class $method $caller $argv1 $argv2 ... $argvN run_class() { - local method="$1" - local caller="$2" + local method="${GLOBAL_ARGV[0]}" + local caller="${GLOBAL_ARGV[1]}" local class local cmd - local argv + local i + local count if valid_session then class="${caller%.*}" cmd="${caller#*.}" - argv="${@/${caller}/}" # remove caller - argv="${argv/${method}/}" # remove method -# echo "method=${method}" -# echo "caller=${caller}" -# echo "class=${class}" -# echo "cmd=${cmd}" -# echo "argv=${argv}" + # copy GLOBAL_ARGV to CLASS_ARGV array without method and caller.class + unset CLASS_ARGV + count="${#GLOBAL_ARGV[*]}" + for (( i=2; i> ${CONFIG} -} - -clearconfig() -{ - if [[ -z ${CONFIG} ]] - then - eecho "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 -} - require() { local requires="$@" @@ -209,7 +175,8 @@ # show missing and set the right retval if [[ -z ${missing} ]] then - rvecho "${sorted}" + # do not escape, or CRLFS get printed to screen too + rvecho ${sorted} return 0 else for req in ${sorted} @@ -217,12 +184,14 @@ if no_duplicate "${missing}" "$req" then # print normal - rvecho -n " ${req}" + rvecho -n "${req} " else # print missing - eecho -n " ${req}" + eecho -n "${req} " fi done + # print CRLF + echo return 1 fi } @@ -254,100 +223,53 @@ rvecho ${sorted} } -# message only echo | disabled in quiet mode -mecho() +is_provided() { - local COLCYAN="\033[1;36m" - local COLDEFAULT="\033[0m" - local opts - local webcrlf - - # print nothing if quiet mode was requested - [[ ${QUIET} = true ]] && return - - if [[ ${NOCOLORS} = true ]] - then - COLCYAN="" - COLDEFAULT="" - fi - - [[ ${WEBCRLF} = true ]] && webcrlf="
" + local feature="$1" + local i + local retval - # respect -n - case $1 in - -n) shift; opts="n" ;; - esac + retval=1 + for i in $(print_provide) + do + if [[ ${i} = ${feature} ]] + then + retval=0 + break + fi + done - echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}" + return "${retval}" } -# prints error messages | enabled even in quiet mode -eecho() +help_daemon_mroot() { - local COLRED="\033[1;31m" - local COLDEFAULT="\033[0m" - local opts - local webcrlf - - if [[ ${NOCOLORS} = true ]] - then - COLRED="" - COLDEFAULT="" - fi - - [[ ${WEBCRLF} = true ]] && webcrlf="
" - - # respect -n - case $1 in - -n) shift; opts="n" ;; - esac - - echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}" + mecho "get daemon.mroot" + mecho " Prints current MROOT variable." + mecho + mecho "set daemon.mroot [path]" + mecho " set MROOT variable to given path." } -# prints return values of get | enabled even in quiet mode -rvecho() +get_daemon_mroot() { - local COLPURPLE="\033[1;35m" - local COLDEFAULT="\033[0m" - local opts - local webcrlf - - if [[ ${NOCOLORS} = true ]] - then - COLPURPLE="" - COLDEFAULT="" - fi - - [[ ${WEBCRLF} = true ]] && webcrlf="
" - - # respect -n - case $1 in - -n) shift; opts="n" ;; - esac - - echo -e${opts} "${COLPURPLE}$@${COLDEFAULT}${webcrlf}" + rvecho "${MROOT}" } -# prints debug messages if requested | enabled even in quiet mode -decho() +set_daemon_mroot() { - # print nothing if debug mode was *not* requested - [[ ${DEBUG} != 1 ]] && return + local path=$1 - eecho "DEBUG: ${@}" + if [[ -d ${path} ]] + then + export MROOT="${path}" + decho "MROOT='${MROOT}' is set." + else + eecho "Path '${path}' does not exist. MROOT not set." + fi } -path_not_empty() +print_version() { - local path="$1" - [[ -z ${path} ]] && eecho "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 + echo "mcored-$(<${MCORE_LIBDIR}/VERSION)" }