X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Fresources%2Fscripts%2Foperation_signal.sh;h=04684bd8ce0482031b8a1330ea7116451b341c42;hb=1ac015cbbcd331edc3c14de26290d669d91e4e53;hp=11cd8e55cc944087af72589e40d1b293a3110993;hpb=75e01e90ae4e1f29813eabe40c3e6b5eea8457bf;p=anna.git diff --git a/example/diameter/launcher/resources/scripts/operation_signal.sh b/example/diameter/launcher/resources/scripts/operation_signal.sh index 11cd8e5..04684bd 100755 --- a/example/diameter/launcher/resources/scripts/operation_signal.sh +++ b/example/diameter/launcher/resources/scripts/operation_signal.sh @@ -16,16 +16,19 @@ _exit() { usage() { echo - echo "Usage: $0 [-h|--help] [-t|--timeout ] [-f|--file] " + echo "Usage: $0 [-h|--help] [-t|--timeout ] [-f|--file] [-p|--ping] " echo echo " -h|--help: this usage help." echo " -t|--timeout: timeout for operation in seconds." - echo " Defaults to 2 seconds if not provided." + echo " Defaults to $TIMEOUT__dflt seconds if not provided." echo echo " -f|--file: the parameter 'data' will be interpreted as a file" echo " with one operation per line. If missing, it will be" echo " a single operation string." echo + echo " -p|--ping: Check the target process id." + echo " Returns 1 (dead) or 0 (alive)." + echo echo " data: operation string or file with several operations." echo echo " For example:" @@ -40,6 +43,7 @@ parse_arguments() { is_file= timeout=$TIMEOUT__dflt data= + ping= while [ $# -gt 0 ]; do case $1 in @@ -61,6 +65,10 @@ parse_arguments() { shift ;; + -p|--ping) + ping=yes + ;; + *) first=$(echo $1 | cut -c1) [ "$first" = "-" ] && _exit "Unsupported script option: $1. Type '$SCR_BN -h' (or --help) to print the available options." @@ -70,13 +78,13 @@ parse_arguments() { shift done - [ -z "$data" ] && _exit "Missing data value" + [ -z "$ping" -a -z "$data" ] && _exit "Missing data value" } # $1: pid to check check_pid() { kill -0 $1 2>/dev/null - [ $? -ne 0 ] && _exit "Operation error: missing process with pid $1" + return $? } ############# @@ -91,14 +99,20 @@ PID=`cat .pid` [ "$1" = "" -o "$1" = "--help" -o "$1" = "-h" ] && usage parse_arguments $@ +# Check pid: +check_pid $PID +res=$? +[ -n "$ping" ] && exit $res +[ $res -ne 0 ] && _exit "Operation error: missing process with pid $PID" + # Send operation: if [ -n "$is_file" ] then - grep -v "^#" $data | sed '/^[ \t]*$/d' > sigusr2.in + cp $data sigusr2.in else echo $data > sigusr2.in fi -0> sigusr2.out +0>sigusr2.out check_pid $PID kill -s SIGUSR2 $PID @@ -122,7 +136,7 @@ else _exit "Operation error: timeout expired ($timeout seconds)" fi -exception=$(grep exception sigusr2.out) -[ $? -eq 0 -a "$data" != "help" ] && _exit "(detected 'exception' within operation output)" +exception=$(grep "^Operation processed with exception: " sigusr2.out) +[ $? -eq 0 ] && _exit "(detected 'exception' within operation output: see 'launcher.trace')" exit 0