Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | |
| 3 | # Change this accordingly |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 4 | ONOS_HOME=${ONOS_HOME:-${HOME}/ONOS} |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 5 | script_name="topology_rest.py" |
| 6 | |
| 7 | ####################### |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 8 | WEBDIR=${ONOS_HOME}/web |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 9 | restscript=${WEBDIR}/$script_name |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 10 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 11 | REST_LOG="${LOGDIR}/rest.`hostname`.log" |
| 12 | ####################### |
| 13 | |
Ubuntu | b92ae40 | 2013-04-05 02:11:40 +0000 | [diff] [blame] | 14 | dokill() { |
| 15 | for cpid in $(ps -o pid= --ppid $1) |
| 16 | do |
| 17 | dokill $cpid |
| 18 | done |
| 19 | echo "killing: $(ps -p $1 -o cmd=)" |
| 20 | kill -9 $1 > /dev/null 2>&1 |
| 21 | } |
| 22 | |
| 23 | |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 24 | function lotate { |
| 25 | logfile=$1 |
| 26 | nr_max=${2:-10} |
| 27 | if [ -f $logfile ]; then |
| 28 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 29 | if [ -f ${logfile}.${i} ]; then |
| 30 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 31 | fi |
| 32 | done |
| 33 | mv $logfile $logfile.1 |
| 34 | fi |
| 35 | } |
| 36 | |
| 37 | function stop { |
| 38 | pids=`ps -edalf |grep ${script_name} | grep python | grep -v grep | awk '{print $4}'` |
| 39 | for p in ${pids}; do |
| 40 | if [ x$p != "x" ]; then |
Ubuntu | b92ae40 | 2013-04-05 02:11:40 +0000 | [diff] [blame] | 41 | dokill $p |
| 42 | # sudo kill -KILL $p |
| 43 | # echo "Killed existing prosess (pid: $p)" |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 44 | fi |
| 45 | done |
| 46 | } |
| 47 | |
| 48 | function status { |
| 49 | nr_process=`ps -edalf |grep ${script_name} | grep python | grep -v grep | wc -l` |
Ubuntu | b92ae40 | 2013-04-05 02:11:40 +0000 | [diff] [blame] | 50 | if [ ${nr_process} != 0 ] ; then |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 51 | echo "rest server is running" |
| 52 | else |
| 53 | echo "rest server is not running" |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 54 | fi |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | function start { |
| 58 | lotate $REST_LOG 10 |
| 59 | cd $WEBDIR |
Masayoshi Kobayashi | 640ad69 | 2014-01-22 23:37:59 -0800 | [diff] [blame] | 60 | # Make log dir for iperf log files |
| 61 | if [ ! -d log ]; then |
| 62 | mkdir log |
| 63 | fi |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 64 | $restscript > $REST_LOG 2>&1 & |
| 65 | } |
| 66 | |
| 67 | case "$1" in |
| 68 | start) |
| 69 | stop |
Masayoshi Kobayashi | 7abb3a9 | 2013-03-21 22:46:04 +0000 | [diff] [blame] | 70 | sleep 2 |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 71 | start |
| 72 | ;; |
| 73 | stop) |
| 74 | stop |
| 75 | ;; |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 76 | status) |
| 77 | status |
| 78 | ;; |
| 79 | *) |
Yuta HIGUCHI | 645a668 | 2014-01-02 11:10:12 -0800 | [diff] [blame] | 80 | echo "Usage: $0 {start|stop|status}" |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 81 | exit 1 |
| 82 | esac |