blob: 564eccf88a1fdb70773dd2dcd29bb4396e1e4b73 [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
14function lotate {
15 logfile=$1
16 nr_max=${2:-10}
17 if [ -f $logfile ]; then
18 for i in `seq $(expr $nr_max - 1) -1 1`; do
19 if [ -f ${logfile}.${i} ]; then
20 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
21 fi
22 done
23 mv $logfile $logfile.1
24 fi
25}
26
27function stop {
28 pids=`ps -edalf |grep ${script_name} | grep python | grep -v grep | awk '{print $4}'`
29 for p in ${pids}; do
30 if [ x$p != "x" ]; then
31 sudo kill -KILL $p
32 echo "Killed existing prosess (pid: $p)"
33 fi
34 done
35}
36
37function status {
38 nr_process=`ps -edalf |grep ${script_name} | grep python | grep -v grep | wc -l`
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +000039 if [ x${nr_process} != "x" ] ; then
40 echo "rest server is running"
41 else
42 echo "rest server is not running"
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000043 fi
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000044}
45
46function start {
47 lotate $REST_LOG 10
48 cd $WEBDIR
49 $restscript > $REST_LOG 2>&1 &
50}
51
52case "$1" in
53 start)
54 stop
Masayoshi Kobayashi7abb3a92013-03-21 22:46:04 +000055 sleep 2
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000056 start
57 ;;
58 stop)
59 stop
60 ;;
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000061 status)
62 status
63 ;;
64 *)
65 echo "Usage: $0 {start|stop|restart|status}"
66 exit 1
67esac