blob: 92718a1226ef29885b0f085ddbc6267cc46429fe [file] [log] [blame]
Naoki Shiotad5d0e942014-03-27 18:57:32 -07001#! /bin/bash
2
3# Change this accordingly
4ONOS_HOME=${ONOS_HOME:-${HOME}/ONOS}
5SCRIPT_NAME="topology_rest.py"
6
7#######################
8SCRIPT_DIR=${ONOS_HOME}/sample/ONS2014demo/scripts
9REST_SCRIPT=${SCRIPT_DIR}/${SCRIPT_NAME}
10LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
11REST_LOG="${LOGDIR}/ons2014demo_rest.`hostname`.log"
12#######################
13
14dokill() {
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
24function rotate {
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
41 dokill $p
42# sudo kill -KILL $p
43# echo "Killed existing prosess (pid: $p)"
44 fi
45 done
46}
47
48function status {
49 nr_process=`ps -edalf | grep ${SCRIPT_NAME} | grep python | grep -v grep | wc -l`
50 if [ ${nr_process} != 0 ] ; then
51 echo "rest server is running"
52 else
53 echo "rest server is not running"
54 fi
55}
56
57function start {
58 rotate $REST_LOG 10
59 cd ${SCRIPT_DIR}
60 # Make log dir for iperf log files
61 if [ ! -d log ]; then
62 mkdir log
63 fi
64 $REST_SCRIPT > $REST_LOG 2>&1 &
65}
66
67case "$1" in
68 start)
69 stop
70 sleep 2
71 start
72 ;;
73 stop)
74 stop
75 ;;
76 status)
77 status
78 ;;
79 *)
80 echo "Usage: $0 {start|stop|status}"
81 exit 1
82esac