blob: a79a415c3a54a5871f55c30f4d951dcc7dda544b [file] [log] [blame]
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +00001#! /bin/bash
2
3# Change this accordingly
Yoshi Muroi002c0fa2014-02-25 11:50:24 -08004ONOSDIR=${ONOS_HOME:-${HOME}/ONOS}
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +00005script_name="topology_rest.py"
6
7#######################
8WEBDIR=${ONOSDIR}/web
9restscript=${WEBDIR}/$script_name
Yoshi Muroi002c0fa2014-02-25 11:50:24 -080010LOGDIR=${ONOS_LOGDIR:-${ONOSDIR}/onos-logs}
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000011REST_LOG="${LOGDIR}/rest.`hostname`.log"
12#######################
13
Ubuntub92ae402013-04-05 02:11:40 +000014dokill() {
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 Kobayashi274c07d2013-02-20 21:38:16 +000024function 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
37function 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
Ubuntub92ae402013-04-05 02:11:40 +000041 dokill $p
42# sudo kill -KILL $p
43# echo "Killed existing prosess (pid: $p)"
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000044 fi
45 done
46}
47
48function status {
49 nr_process=`ps -edalf |grep ${script_name} | grep python | grep -v grep | wc -l`
Ubuntub92ae402013-04-05 02:11:40 +000050 if [ ${nr_process} != 0 ] ; then
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +000051 echo "rest server is running"
52 else
53 echo "rest server is not running"
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000054 fi
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000055}
56
57function start {
58 lotate $REST_LOG 10
59 cd $WEBDIR
Masayoshi Kobayashi640ad692014-01-22 23:37:59 -080060 # Make log dir for iperf log files
61 if [ ! -d log ]; then
62 mkdir log
63 fi
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000064 $restscript > $REST_LOG 2>&1 &
65}
66
67case "$1" in
68 start)
69 stop
Masayoshi Kobayashi7abb3a92013-03-21 22:46:04 +000070 sleep 2
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000071 start
72 ;;
73 stop)
74 stop
75 ;;
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000076 status)
77 status
78 ;;
79 *)
Yuta HIGUCHI645a6682014-01-02 11:10:12 -080080 echo "Usage: $0 {start|stop|status}"
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000081 exit 1
82esac