blob: e29a05d6170317e5315515a8ddd09ea96fb07f45 [file] [log] [blame]
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +00001#! /bin/bash
2
3# Change this accordingly
Bob Lantz63bbe4c2014-02-06 19:29:55 -08004ONOS_HOME=${ONOS_HOME:-${HOME}/ONOS}
Jonathan Hart444256d2014-05-12 22:13:39 -07005script_name="simple_web_server.py"
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +00006
7#######################
Bob Lantz63bbe4c2014-02-06 19:29:55 -08008WEBDIR=${ONOS_HOME}/web
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +00009restscript=${WEBDIR}/$script_name
Bob Lantz63bbe4c2014-02-06 19:29:55 -080010LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/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
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000042 fi
43 done
44}
45
46function status {
47 nr_process=`ps -edalf |grep ${script_name} | grep python | grep -v grep | wc -l`
Ubuntub92ae402013-04-05 02:11:40 +000048 if [ ${nr_process} != 0 ] ; then
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +000049 echo "rest server is running"
50 else
51 echo "rest server is not running"
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000052 fi
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000053}
54
55function start {
56 lotate $REST_LOG 10
57 cd $WEBDIR
58 $restscript > $REST_LOG 2>&1 &
59}
60
61case "$1" in
62 start)
63 stop
Masayoshi Kobayashi7abb3a92013-03-21 22:46:04 +000064 sleep 2
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000065 start
66 ;;
67 stop)
68 stop
69 ;;
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000070 status)
71 status
72 ;;
73 *)
Yuta HIGUCHI645a6682014-01-02 11:10:12 -080074 echo "Usage: $0 {start|stop|status}"
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000075 exit 1
76esac