blob: 1f801fedf4aa407b039689e8c9ac31a8c3ad755d [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
55 start
56 ;;
57 stop)
58 stop
59 ;;
60 deldb)
61 deldb
62 ;;
63 status)
64 status
65 ;;
66 *)
67 echo "Usage: $0 {start|stop|restart|status}"
68 exit 1
69esac