blob: 01e7638a3f1ae8a236c621047b6148a5a158a578 [file] [log] [blame]
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +00001#! /bin/bash
2
3# Change this accordingly
4ONOSDIR=${HOME}/ONOS
5script_name="topology_rest.py"
6
7#######################
8WEBDIR=${ONOSDIR}/web
9restscript=${WEBDIR}/$script_name
10LOGDIR=${ONOSDIR}/onos-logs
11REST_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
60 $restscript > $REST_LOG 2>&1 &
61}
62
63case "$1" in
64 start)
65 stop
Masayoshi Kobayashi7abb3a92013-03-21 22:46:04 +000066 sleep 2
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000067 start
68 ;;
69 stop)
70 stop
71 ;;
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000072 status)
73 status
74 ;;
75 *)
76 echo "Usage: $0 {start|stop|restart|status}"
77 exit 1
78esac