--- mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2011/02/16 18:24:35 1330 +++ mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in 2015/09/17 07:27:10 2555 @@ -1,5 +1,43 @@ # $Id$ +# 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 class in $(find ${MCORE_LIBDIR}/include -type f -name \*.${classtype}.class) + do + include ${class} || eecho "error loading ${class}" + done +} + +# restarts the whole service via remote cmd +restart_service() +{ + local pid + for pid in $(pidof sslsvd) + do + kill -SIGHUP ${pid} + 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() # { @@ -20,37 +58,59 @@ # 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 - 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 -} - require() { local requires="$@" @@ -154,7 +161,7 @@ then export REQUIRE="${REQUIRE} ${i}" else - [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" + decho "duplicate provide '${i}' detected!" fi done } @@ -183,7 +190,8 @@ # show missing and set the right retval if [[ -z ${missing} ]] then - mecho "${sorted}" + # do not escape, or CRLFS get printed to screen too + rvecho ${sorted} return 0 else for req in ${sorted} @@ -191,12 +199,14 @@ if no_duplicate "${missing}" "$req" then # print normal - mecho -n " ${req}" + rvecho -n "${req} " else # print missing - eecho -n " ${req}" + eecho -n "${req} " fi done + # print CRLF + echo return 1 fi } @@ -213,7 +223,7 @@ then export PROVIDE="${PROVIDE} ${i}" else - [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" + decho "duplicate provide '${i}' detected!" fi done } @@ -225,65 +235,83 @@ # sort them alpabetically sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) # do not escape, or CRLFS get printed to screen too - mecho ${sorted} + rvecho ${sorted} } -mecho() +is_provided() { - local COLCYAN="\033[1;36m" - local COLDEFAULT="\033[0m" - local opts - local webcrlf + local feature="$1" + local i + local retval - if [[ ${NOCOLORS} = true ]] - then - COLCYAN="" - COLDEFAULT="" - fi + retval=1 + for i in $(print_provide) + do + if [[ ${i} = ${feature} ]] + then + retval=0 + break + fi + done - [[ ${WEBCRLF} = true ]] && webcrlf="
" + return "${retval}" +} - # respect -n - case $1 in - -n) shift; opts="n" ;; - esac +push_config() +{ + local push_configs="$@" + local i - echo -e${opts} "${COLCYAN}$@${COLDEFAULT}${webcrlf}" + for i in ${push_configs} + do + # check for duplicate provides + if no_duplicate "${PUSH_CONFIG}" "${i}" + then + export PUSH_CONFIG="${PUSH_CONFIG} ${i}" + else + decho "duplicate push_config '${i}' detected!" + fi + done } -eecho() +print_push_config() { - local COLRED="\033[1;31m" - local COLDEFAULT="\033[0m" - local opts - local webcrlf - - if [[ ${NOCOLORS} = true ]] - then - COLRED="" - COLDEFAULT="" - fi + local sorted - [[ ${WEBCRLF} = true ]] && webcrlf="
" + # sort them alpabetically + sorted=$(for i in ${PUSH_CONFIG}; do echo "${i}"; done | sort) + # do not escape, or CRLFS get printed to screen too + rvecho ${sorted} +} - # respect -n - case $1 in - -n) shift; opts="n" ;; - esac +help_daemon_mroot() +{ + mecho "get daemon.mroot" + mecho " Prints current MROOT variable." + mecho + mecho "set daemon.mroot [path]" + mecho " set MROOT variable to given path." +} - echo -e${opts} "${COLRED}$@${COLDEFAULT}${webcrlf}" +get_daemon_mroot() +{ + rvecho "${MROOT}" } -path_not_empty() +set_daemon_mroot() { - local path="$1" - [[ -z ${path} ]] && "path_not_empty(): no path given!" && return 1 + local path=$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 + if [[ -d ${path} ]] + then + export MROOT="${path}" + decho "MROOT='${MROOT}' is set." + else + eecho "Path '${path}' does not exist. MROOT not set." + fi +} - # every thing went ok, directory not empty - return 0 +print_version() +{ + echo "mcored-$(<${MCORE_LIBDIR}/VERSION)" }