--- mcore-src/trunk/mcore-tools/daemon/include/daemon.global.class 2011/02/02 20:20:24 1248 +++ mcore-src/trunk/mcore-tools/src/include/daemon.global.class.in 2014/07/03 11:17:03 2318 @@ -1,50 +1,95 @@ # $Id$ -# import_resource $table $serial $resource $value -import_resource() +# loads client classes from $MCORE_LIBDIR +load_classes() { - local table="$1" - local serial="$2" - local resource="$3" - local value="$4" + local class + local classtype - if [[ ${DEBUG} = 1 ]] - then - echo "${table}->${resource}=${value}" >> /root/lala.log - echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log - fi + 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 +} - mysql_insert "${table}",serial="${serial}","${resource}"="${value}" +# 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() +# { +# local table="$1" +# local serial="$2" +# local resource="$3" +# local value="$4" +# +# if [[ ${DEBUG} = 1 ]] +# then +# echo "${table}->${resource}=${value}" >> /root/lala.log +# echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log +# fi +# +# mysql_insert "${table}",serial="${serial}","${resource}"="${value}" +# } + # 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 validate_session + 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 - - : > ${CONFIG} + mecho + mecho "Type 'help [topic]' for more information about every topic." } require() @@ -116,21 +140,59 @@ for i in ${requires} do - export REQUIRE="${REQUIRE} ${i}" + # check for duplicate provides + if no_duplicate "${PROVIDE}" "${i}" + then + export REQUIRE="${REQUIRE} ${i}" + else + decho "duplicate provide '${i}' detected!" + fi done } -not_provided() +verify_requirements() { - local i - local item="$1" + local req + local prov + local missing + local sorted - for i in ${PROVIDE} + for req in ${REQUIRE} do - [[ ${i} = ${item} ]] && return 1 + # scan PROVIDE for dupes + # if a dupe is found, then requirement is fullfilled + # else add to missing + if no_duplicate "${PROVIDE}" "${req}" + then + missing="${missing} ${req}" + fi done - return 0 + # sort them alpabetically + sorted=$(for i in ${REQUIRE}; do echo "${i}"; done | sort) + + # show missing and set the right retval + if [[ -z ${missing} ]] + then + # do not escape, or CRLFS get printed to screen too + rvecho ${sorted} + return 0 + else + for req in ${sorted} + do + if no_duplicate "${missing}" "$req" + then + # print normal + rvecho -n "${req} " + else + # print missing + eecho -n "${req} " + fi + done + # print CRLF + echo + return 1 + fi } provide() @@ -141,11 +203,11 @@ for i in ${provides} do # check for duplicate provides - if not_provided "${i}" + if no_duplicate "${PROVIDE}" "${i}" then export PROVIDE="${PROVIDE} ${i}" else - [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" + decho "duplicate provide '${i}' detected!" fi done } @@ -157,18 +219,56 @@ # 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} +} + +is_provided() +{ + local feature="$1" + local i + local retval + + retval=1 + for i in $(print_provide) + do + if [[ ${i} = ${feature} ]] + then + reval=0 + break + fi + done + + return "${retval}" +} + +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." +} + +get_daemon_mroot() +{ + rvecho "${MROOT}" } -mecho() +set_daemon_mroot() { - local COLCYAN="\033[1;36m" - local COLDEFAULT="\033[0m" - if [[ ${NOCOLORS} = true ]] + local path=$1 + + if [[ -d ${path} ]] then - COLCYAN="" - COLDEFAULT="" + export MROOT="${path}" + decho "MROOT='${MROOT}' is set." + else + eecho "Path '${path}' does not exist. MROOT not set." fi +} - echo -e "${COLCYAN}$@${COLDEFAULT}" +print_version() +{ + echo "mcored-$(<${MCORE_LIBDIR}/VERSION)" }