#! /usr/bin/env bash # # Copyright (C) 2012 NEC Corporation # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # EXECUTABLES_DIR="$TREMA_HOME/objects/management" ECHO="$EXECUTABLES_DIR/echo" SET_LOGGING_LEVEL="$EXECUTABLES_DIR/set_logging_level" SHOW_STATS="$EXECUTABLES_DIR/show_stats" APPLICATION="$EXECUTABLES_DIR/application" SOCK_DIR="$TREMA_HOME/tmp/sock" BASENAME="/usr/bin/basename" SED="/bin/sed" SCRIPT_NAME=`$BASENAME $0` list_services() { shopt -s nullglob for file in $SOCK_DIR/*.m.sock do echo `$BASENAME $file .m.sock | $SED 's/^trema\.//'` done } ping() { local service_name="$1" if [ -z "$service_name" ]; then echo "Service name must be specified." print_ping_usage exit 1 fi $ECHO $service_name } set_logging_level() { local service_name="$1" local logging_level="$2" if [ -z "$service_name" ]; then echo "Service name must be specified." print_set_logging_level_usage exit 1 fi if [ -z "$logging_level" ]; then echo "Logging level must be specified." print_set_logging_level_usage exit 1 fi $SET_LOGGING_LEVEL $service_name $logging_level } show_stats() { local service_name="$1" if [ -z "$service_name" ]; then echo "Service name must be specified." print_show_stats_usage exit 1 fi $SHOW_STATS $service_name } application() { local service_name="$1" local application_id="$2" local data="$3" if [ -z "$service_name" ]; then echo "Service name must be specified." print_application_usage exit 1 fi if [ -z "$application_id" ]; then echo "Application specific identifier must be specified." print_application_usage exit 1 fi $APPLICATION $service_name $application_id $data } check_variables() { if [ -z "$TREMA_HOME" ]; then echo "TREMA_HOME environment variable must be set." exit 1 fi if [ ! -d "$TREMA_HOME" ]; then echo "$TREMA_HOME does not exist." exit 1 fi if [ ! -d "$SOCK_DIR" ]; then echo "$SOCK_DIR does not exist." exit 1 fi if [ ! -d "$EXECUTABLES_DIR" ]; then echo "$EXECUTABLES_DIR does not exist." exit 1 fi } print_list_services_usage() { echo "Usage: $SCRIPT_NAME services" } print_usage() { echo "Usage: $SCRIPT_NAME {services|ping|set_logging_level|show_stats|application} [OPTIONS...]" } print_ping_usage() { echo "Usage: $SCRIPT_NAME ping SERVICE_NAME" } print_set_logging_level_usage() { echo "Usage: $SCRIPT_NAME set_logging_level SERVICE_NAME LOGGING_LEVEL" } print_show_stats_usage() { echo "Usage: $SCRIPT_NAME show_stats SERVICE_NAME" } print_application_usage() { echo "Usage: $SCRIPT_NAME application SERVICE_NAME APPLICATION_ID DATA_IN_HEX" } check_variables case "$1" in services) list_services ;; ping) ping $2 ;; set_logging_level) set_logging_level $2 $3 ;; show_stats) show_stats $2 ;; application) application $2 $3 $4 ;; *) print_usage exit 1 esac exit 0