Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | |
| 3 | # Change this accordingly |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 4 | ONOS_HOME=${ONOS_HOME:-${HOME}/ONOS} |
Jonathan Hart | 444256d | 2014-05-12 22:13:39 -0700 | [diff] [blame] | 5 | script_name="simple_web_server.py" |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 6 | |
| 7 | ####################### |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 8 | WEBDIR=${ONOS_HOME}/web |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 9 | restscript=${WEBDIR}/$script_name |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 10 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 11 | REST_LOG="${LOGDIR}/rest.`hostname`.log" |
| 12 | ####################### |
| 13 | |
Ubuntu | b92ae40 | 2013-04-05 02:11:40 +0000 | [diff] [blame] | 14 | dokill() { |
| 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 Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 24 | function 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 | |
| 37 | function 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 |
Ubuntu | b92ae40 | 2013-04-05 02:11:40 +0000 | [diff] [blame] | 41 | dokill $p |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 42 | fi |
| 43 | done |
| 44 | } |
| 45 | |
| 46 | function status { |
| 47 | nr_process=`ps -edalf |grep ${script_name} | grep python | grep -v grep | wc -l` |
Ubuntu | b92ae40 | 2013-04-05 02:11:40 +0000 | [diff] [blame] | 48 | if [ ${nr_process} != 0 ] ; then |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 49 | echo "rest server is running" |
| 50 | else |
| 51 | echo "rest server is not running" |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 52 | fi |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | function start { |
| 56 | lotate $REST_LOG 10 |
| 57 | cd $WEBDIR |
| 58 | $restscript > $REST_LOG 2>&1 & |
| 59 | } |
| 60 | |
| 61 | case "$1" in |
| 62 | start) |
| 63 | stop |
Masayoshi Kobayashi | 7abb3a9 | 2013-03-21 22:46:04 +0000 | [diff] [blame] | 64 | sleep 2 |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 65 | start |
| 66 | ;; |
| 67 | stop) |
| 68 | stop |
| 69 | ;; |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 70 | status) |
| 71 | status |
| 72 | ;; |
| 73 | *) |
Yuta HIGUCHI | 645a668 | 2014-01-02 11:10:12 -0800 | [diff] [blame] | 74 | echo "Usage: $0 {start|stop|status}" |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 75 | exit 1 |
| 76 | esac |