Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | |
| 3 | # Change this accordingly |
| 4 | ONOSDIR=${HOME}/ONOS |
| 5 | script_name="topology_rest.py" |
| 6 | |
| 7 | ####################### |
| 8 | WEBDIR=${ONOSDIR}/web |
| 9 | restscript=${WEBDIR}/$script_name |
| 10 | LOGDIR=${ONOSDIR}/onos-logs |
| 11 | REST_LOG="${LOGDIR}/rest.`hostname`.log" |
| 12 | ####################### |
| 13 | |
| 14 | function 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 | |
| 27 | function 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 | |
| 37 | function status { |
| 38 | nr_process=`ps -edalf |grep ${script_name} | grep python | grep -v grep | wc -l` |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 39 | if [ x${nr_process} != "x" ] ; then |
| 40 | echo "rest server is running" |
| 41 | else |
| 42 | echo "rest server is not running" |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 43 | fi |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | function start { |
| 47 | lotate $REST_LOG 10 |
| 48 | cd $WEBDIR |
| 49 | $restscript > $REST_LOG 2>&1 & |
| 50 | } |
| 51 | |
| 52 | case "$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 |
| 69 | esac |