From bfd365eb17ec248eba2ed565e5efe1b30240d9c7 Mon Sep 17 00:00:00 2001 From: davor Date: Thu, 9 Oct 2014 18:00:22 +0200 Subject: Added otcheck and minor fixes. --- ot-tools-user.sh | 227 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 123 insertions(+), 104 deletions(-) diff --git a/ot-tools-user.sh b/ot-tools-user.sh index 6680389..f5e6366 100644 --- a/ot-tools-user.sh +++ b/ot-tools-user.sh @@ -6,6 +6,27 @@ otconfig() { . $OT_PREFIX/install/utils.sh } +# configure tab completion for ottools +_ottoolcompletion() +{ + word="${COMP_WORDS[COMP_CWORD]}" + COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W ' + all + algorithm + compound + dataset + feature + model + task + validation + 4store + ' "$word")) ; +} +complete -o default -F _ottoolcompletion otstart +#complete -o default -F _ottoolcompletion otreload +complete -o default -F _ottoolcompletion otkill +complete -o default -F _ottoolcompletion otcheck + # Display log alias otless='less $HOME/.opentox/log/development.log' @@ -19,40 +40,21 @@ alias ottail='tail -f $HOME/.opentox/log/development.log' start_unicorn() { cd $HOME/opentox-ruby/$1 nice bash -c "nohup unicorn -p $2 >/dev/null 2>&1 &" + sleep 0.5 + check_service $1 online } -# Start unicorn +# Start 4Store # @param1 [backend_name] # @param2 integer Port -# @example start_unicorn algorithm 8081 +# @example start_4s opentox 9088 start_4s() { nice bash -c "nohup $OT_PREFIX/4S/bin/4s-backend $1 >/dev/null 2>&1 &"; sleep 4; nice bash -c "nohup $OT_PREFIX/4S/bin/4s-httpd -p $2 -s -1 $1 >/dev/null 2>&1 &"; #-D for testing sleep 1; - -} - -# configure tab completion for ottools -_ottoolcompletion() -{ - word="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W ' - all - algorithm - compound - dataset - feature - model - task - validation - 4store - ' "$word")) ; + check_service four_store online } -complete -o default -F _ottoolcompletion otstart -#complete -o default -F _ottoolcompletion otreload -complete -o default -F _ottoolcompletion otkill -#complete -o default -F _ottoolcompletion otcheck # Start the server otstart() { @@ -80,15 +82,16 @@ otstart() { nice bash -c "nohup redis-server $OT_PREFIX/validation/redis-*/redis.conf >/dev/null 2>&1 &";; "4store") start_4s opentox 9088; if ! pgrep -u $USER 4s-backend>/dev/null 2>&1; then echo "Failed to start 4s-backend."; fi - if ! pgrep -u $USER 4s-httpd>/dev/null 2>&1; then echo "Failed to start 4s-httpd."; fi;; + if ! pgrep -u $USER 4s-httpd>/dev/null 2>&1; then echo "Failed to start 4s-httpd."; fi; + otcheck 4store;; "all") otstart 4store; - otstart compound; otstart dataset; - otstart feature; otstart model; otstart task; - otstart algorithm; - otstart validation;; + otstart algorithm; #compound and feature is included + otstart validation; + sleep 1; + otcheck all;; *) echo "One argument required: [service_name] or 'all'"; echo "usage: otstart [all|algorithm|compound|dataset|feature|model|task|validation|4store]"; return 1;; @@ -161,6 +164,8 @@ otstart() { # @example kill_unicorn 8081 kill_unicorn() { for p in `ps x | grep 'unicorn' | grep $1 | grep -v grep | awk '{print $1}'`; do kill -3 $p; done; + sleep 0.5 + for p in `ps x | grep 'unicorn' | grep $1 | grep -v grep | awk '{print $1}'`; do echo "Process with PID $p is still running and belongs to port $1. Please wait and run otkill again."; done; } # Kill the server @@ -201,88 +206,102 @@ otkill() { # sets $SERVICE_URI if found in config files # @param1 string [service_name] # @example get_service_uri algorithm -#get_service_uri() { -# if [ $# != 1 ]; then -# echo "One argument required: [service_name]" -# echo "usage: get_service_uri [algorithm|compound|dataset|feature|model|task|validation|four_store]" -# return 1 -# fi -# SERVICE_URI="" -# -# if [ -f $HOME/.opentox/config/$1.rb ]; then -# SERVICE_URI=`cat $HOME/.opentox/config/$1.rb | grep $1 | grep "uri" | awk -F":uri => " '{print $2}' | awk -F" " '{print $1}' | awk -F"," '{print $1}' | sed "s/'//g" | sed 's/"//g'` -# fi -# -# if [ -f $HOME/.opentox/config/default.rb ]; then -# [ -n "$SERVICE_URI" ] || SERVICE_URI=`cat $HOME/.opentox/config/default.rb | grep $1 | grep "uri" | awk -F":uri => " '{print $2}' | awk -F" " '{print $1}' | awk -F"," '{print $1}' | sed "s/'//g" | sed 's/"//g'` -# fi -# -# if [ -z "$SERVICE_URI" ]; then -# echo "Cannot find service uri for $1 in config files." -# return 1 -# else -# return 0 -# fi -#} +get_service_uri() { + if [ $# != 1 ]; then + echo "One argument required: [service_name]" + echo "usage: get_service_uri [algorithm|compound|dataset|feature|model|task|validation|four_store]" + return 1 + fi + SERVICE_URI="" + + if [ -f $HOME/.opentox/config/$1.rb ]; then + SERVICE_URI=`cat $HOME/.opentox/config/$1.rb | grep $1 | grep "uri" | awk -F":uri => " '{print $2}' | awk -F" " '{print $1}' | awk -F"," '{print $1}' | sed "s/'//g" | sed 's/"//g'` + fi + + if [ -f $HOME/.opentox/config/default.rb ]; then + [ -n "$SERVICE_URI" ] || SERVICE_URI=`cat $HOME/.opentox/config/default.rb | grep $1 | grep "uri" | awk -F":uri => " '{print $2}' | awk -F" " '{print $1}' | awk -F"," '{print $1}' | sed "s/'//g" | sed 's/"//g'` + fi + + if [ -z "$SERVICE_URI" ]; then + echo "Cannot find service uri for $1 in config files." + return 1 + else + return 0 + fi +} -# check service +# Check service # @param1 string [service_name] -# @example check_service algorithm -#check_service() { -# check_utils "curl" -# if [ $# != 1 ]; then -# echo "One argument required: [service_name]" -# echo "usage: get_service_uri [algorithm|compound|dataset|feature|model|task|validation|four_store]" +# @param2 (optinal) string ["online"] ; output for running services +# @example check_service algorithm online +check_service() { + check_utils "curl" + if [ $# != 1 ] && [ $# != 2 ]; then + echo "One argument required: [service_name]. Second argument optional." + echo "usage: check_service [algorithm|compound|dataset|feature|model|task|validation|four_store] [online](optional)" + return 1 + fi + get_service_uri $1 + MY_SERVICE="IST service" + if [[ $1 == "four_store" ]]; then + SERVICE_URI="$SERVICE_URI""/status/" + MY_SERVICE="HTTP service" + fi + if [ -n "`$CURL -i -k -X HEAD $SERVICE_URI 2>&1 | grep '^HTTP' |grep ' 200'`" ]; then + if [[ $2 == "online" ]]; then + echo "$MY_SERVICE $1 is running at $SERVICE_URI." + return 1 + fi + return 0 + else + echo "$MY_SERVICE $1 is NOT available at $SERVICE_URI." + return 1 + fi +} + +#check_all_service_offline() { +# CHECK_RESULT=`otcheck all` +# if [ -z "$CHECK_RESULT" ]; then +# echo "IST service(s) is(are) running." +# otcheck all # return 1 -# fi -# get_service_uri $1 -# HEADER="Accept: */*" -# if [ $1 == "four_store" ]; then -# SERVICE_URI="$SERVICE_URI""/status/" -# fi -# if [ $1 == "compound" ]; then -# SERVICE_URI="$SERVICE_URI""/InChI=1S/BF4.Na/c2-1(3,4)5;/q-1;+1" -# HEADER="Accept: chemical/x-inchi" -# fi -# if [ -n "`$CURL -v -H "$HEADER" $SERVICE_URI 2>&1 | grep '200 OK'`" ]; then -# return 0 # else -# echo "$1 is not available at $SERVICE_URI." -# return 1 +# echo "IST services are offline." # fi #} -# Check the server -#otcheck() { -# if [ $# != 1 ]; then -# echo "One argument required: [service_name] or 'all'" -# echo "usage: otcheck [all|algorithm|compound|dataset|feature|model|task|validation|4store]" -# return 1 -# fi -# -# otconfig -# case "$1" in -# "algorithm") check_service "algorithm";; -# "compound") check_service "compound";; -# "dataset") check_service "dataset";; -# "feature") check_service "feature";; -# "model") check_service "model";; -# "task") check_service "task";; -# "validation") check_service "validation";; -# "4store") check_service "four_store";; -# "all") otcheck "algorithm"; -# otcheck "compound"; -# otcheck "dataset"; -# otcheck "feature"; -# otcheck "model"; -# otcheck "task"; -# otcheck "validation"; -# otcheck 4store;; -# *) echo "One argument required: [service_name] or 'all'"; -# echo "usage: otcheck [all|algorithm|compound|dataset|feature|model|task|validation|4store]"; -# return 1;; -# esac -#} + +# Check response of web service +otcheck() { + if [ $# != 1 ]; then + echo "One argument required: [service_name] or 'all'" + echo "usage: otcheck [all|algorithm|compound|dataset|feature|model|task|validation|4store]" + return 1 + fi + + otconfig + case "$1" in + "algorithm") check_service "algorithm";; + "compound") check_service "compound";; + "dataset") check_service "dataset";; + "feature") check_service "feature";; + "model") check_service "model";; + "task") check_service "task";; + "validation") check_service "validation";; + "4store") check_service "four_store";; + "all") otcheck "algorithm"; + otcheck "compound"; + otcheck "dataset"; + otcheck "feature"; + otcheck "model"; + otcheck "task"; + otcheck "validation"; + otcheck 4store;; + *) echo "One argument required: [service_name] or 'all'"; + echo "usage: otcheck [all|algorithm|compound|dataset|feature|model|task|validation|4store]"; + return 1;; + esac +} # pull repository # @param1 service -- cgit v1.2.3