From 4f2fec4e7e2a53bbc421db5da08f37152495188d Mon Sep 17 00:00:00 2001 From: davor Date: Mon, 13 Aug 2012 16:43:15 +0200 Subject: Fixed otkill, added otreload/otcheck. --- ot-tools-user.sh | 272 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 202 insertions(+), 70 deletions(-) diff --git a/ot-tools-user.sh b/ot-tools-user.sh index bc4a7d0..ca3bdbd 100644 --- a/ot-tools-user.sh +++ b/ot-tools-user.sh @@ -5,6 +5,11 @@ otconfig() { source $HOME/.opentox/opentox-ui.sh } +# Display log +alias otless='less $HOME/.opentox/log/development.log' + +# Tail log +alias ottail='tail -f $HOME/.opentox/log/development.log' # Start unicorn # @param1 [service_name] @@ -28,58 +33,98 @@ otstart() { otkill $1 DIR=`pwd` case "$1" in - "algorithm") - start_unicorn $1 8081;; - "compound") - echo "$1 not available yet.";; - #start_unicorn $1 8082;; - "dataset") - start_unicorn $1 8083;; - "feature") - start_unicorn $1 8084;; - "model") - echo "$1 not available yet.";; - #start_unicorn $1 8085;; - "task") - start_unicorn $1 8086;; - "validation") - echo "$1 not available yet.";; - #start_unicorn $1 8087;; - "4store") - nice bash -c "nohup $HOME/opentox-ruby/4S/bin/4s-backend opentox >/dev/null 2>&1 &"; - sleep 1; - nice bash -c "nohup $HOME/opentox-ruby/4S/bin/4s-httpd -D -H localhost -p 8088 opentox >/dev/null 2>&1 &"; - sleep 1; - 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 - ;; - "all") - otstart 4store; - otstart algorithm; - otstart dataset; - otstart feature; - otstart task; - ;; - *) - echo "One argument required: [service_name] or 'all'"; - echo "usage: otstart [all|algorithm|compound|dataset|feature|model|task|validation|4store]"; - return 1; - ;; + "algorithm") start_unicorn $1 8081;; + "compound") #start_unicorn $1 8082;; + echo "$1 not available yet.";; + "dataset") start_unicorn $1 8083;; + "feature") start_unicorn $1 8084;; + "model") #start_unicorn $1 8085;; + echo "$1 not available yet.";; + "task") start_unicorn $1 8086;; + "validation") #start_unicorn $1 8087;; + echo "$1 not available yet.";; + "4store") nice bash -c "nohup $HOME/opentox-ruby/4S/bin/4s-backend opentox >/dev/null 2>&1 &"; + sleep 1; + nice bash -c "nohup $HOME/opentox-ruby/4S/bin/4s-httpd -D -H localhost -p 8088 opentox >/dev/null 2>&1 &"; + sleep 1; + 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;; + "all") otstart 4store; + otstart algorithm; + #otstart compound; + otstart dataset; + otstart feature; + #otstart model; + otstart task;; + #otstart validation;; + *) echo "One argument required: [service_name] or 'all'"; + echo "usage: otstart [all|algorithm|compound|dataset|feature|model|task|validation|4store]"; + return 1;; esac cd $DIR } -# Display log -alias otless='less $HOME/.opentox/log/development.log' +# reload unicorn +# @param1 integer Port +# @example reload_unicorn 8081 +reload_unicorn() { + for p in `ps x | grep 'unicorn master' | grep $1 | grep -v grep | awk '{print $1}'`; do + kill -12 $p + done + sleep 0.5 + for p in `ps x | grep 'unicorn master (old)' | grep $1 | grep -v grep | awk '{print $1}'`; do + kill -28 $p + done + sleep 0.5 + # ToDo: Check if new master is working properly. + for p in `ps x | grep 'unicorn master (old)' | grep $1 | grep -v grep | awk '{print $1}'`; do + kill -3 $p + done +} -# Tail log -alias ottail='tail -f $HOME/.opentox/log/development.log' +# Reload the server +otreload() { + if [ $# != 1 ] + then + echo "One argument required: [service_name] or 'all'" + echo "usage: otreload [all|algorithm|compound|dataset|feature|model|task|validation|4store]" + return 1 + fi + + otconfig + case "$1" in + "algorithm") reload_unicorn 8081;; + "compound") #reload_unicorn 8082;; + echo "$1 not available yet.";; + "dataset") reload_unicorn 8083;; + "feature") reload_unicorn 8084;; + "model") #reload_unicorn 8085;; + echo "$1 not available yet.";; + "task") reload_unicorn 8086;; + "validation") #reload_unicorn 8087;; + echo "$1 not available yet.";; + "4store") #killall 4s-httpd >/dev/null 2>&1; + #killall 4s-backend >/dev/null 2>&1;; + echo "$1 reload not available yet.";; + "all") otreload algorithm; + #otreload compound; + otreload dataset; + otreload feature; + #otreload model; + otreload task; + #otrelaod validation; + otreload 4store;; + *) echo "One argument required: [service_name] or 'all'"; + echo "usage: otreload [all|algorithm|compound|dataset|feature|model|task|validation|4store]"; + return 1;; + esac +} # kill unicorn # @param1 integer Port # @example kill_unicorn 8081 kill_unicorn() { - for p in `ps x | grep 'unicorn' | grep $1 | grep -v grep | awk '{print $1}'`; do kill -9 $p; done; + for p in `ps x | grep 'unicorn' | grep $1 | grep -v grep | awk '{print $1}'`; do kill -3 $p; done; } # Kill the server @@ -93,34 +138,121 @@ otkill() { otconfig case "$1" in - "algorithm") kill_unicorn 8081;; - "compound") #kill_unicorn 8082;; - echo "$1 not available yet.";; - "dataset") kill_unicorn 8083;; - "feature") kill_unicorn 8084;; - "model") #kill_unicorn 8085;; - echo "$1 not available yet.";; - "task") kill_unicorn 8086;; + "algorithm") kill_unicorn 8081;; + "compound") #kill_unicorn 8082;; + echo "$1 not available yet.";; + "dataset") kill_unicorn 8083;; + "feature") kill_unicorn 8084;; + "model") #kill_unicorn 8085;; + echo "$1 not available yet.";; + "task") kill_unicorn 8086;; "validation") #kill_unicorn 8087;; - echo "$1 not available yet.";; - "4store") - killall 4s-httpd >/dev/null 2>&1; - killall 4s-backend >/dev/null 2>&1; - ;; - "all") - otkill algorithm; - #otkill compound; - otkill dataset; - otkill feature; - #otkill model; - otkill task; - #otkill validation; - otkill 4store; - ;; - *) - echo "One argument required: [service_name] or 'all'"; - echo "usage: otkill [all|algorithm|compound|dataset|feature|model|task|validation|4store]"; - return 1; - ;; + echo "$1 not available yet.";; + "4store") killall 4s-httpd >/dev/null 2>&1; + killall 4s-backend >/dev/null 2>&1;; + "all") otkill algorithm; + #otkill compound; + otkill dataset; + otkill feature; + #otkill model; + otkill task; + #otkill validation; + otkill 4store;; + *) echo "One argument required: [service_name] or 'all'"; + echo "usage: otkill [all|algorithm|compound|dataset|feature|model|task|validation|4store]"; + return 1;; + esac +} + +# get service uri +# 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 +} + +# check service +# @param1 string [service_name] +# @example check_service algorithm +check_service() { + 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 + get_service_uri $1 + if [ $1 == "four_store" ] + then + SERVICE_URI="$SERVICE_URI""/status/" + fi + if [ -n "`curl -v $SERVICE_URI 2>&1 | grep '200 OK'`" ] + then + return 0 + else + echo "$1 is not available at $SERVICE_URI." + return 1 + 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";; + echo "$1 not available yet.";; + "dataset") check_service "dataset";; + "feature") check_service "feature";; + "model") #check_service "model";; + echo "$1 not available yet.";; + "task") check_service "task";; + "validation") #check_service "validation";; + echo "$1 not available yet.";; + "4store") check_service "four_store";; + #killall 4s-backend >/dev/null 2>&1;; + "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 } -- cgit v1.2.3