yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud:${HOME}/ramcloud/obj.blueprint-java |
| 4 | |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 5 | # Set paths |
| 6 | ONOS_HOME=`dirname $0` |
| 7 | RAMCLOUD_DIR=${HOME}/ramcloud |
| 8 | LOGDIR=${ONOS_HOME}/onos-logs |
yoshi | f280640 | 2014-01-23 09:28:39 -0800 | [diff] [blame] | 9 | RAMCLOUD_LOG=${LOGDIR}/ramcloud.coordinator.`hostname`.log |
| 10 | coordinatorip=`grep coordinatorIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 11 | coordinatorport=`grep coordinatorPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 12 | RAMCLOUD_COORDINATOR=`echo $coordinatorip","$coordinatorport` |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 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 start { |
| 28 | if [ ! -d ${LOGDIR} ]; then |
| 29 | mkdir -p ${LOGDIR} |
| 30 | fi |
| 31 | echo "rotate log: $log" |
| 32 | if [ -f $RAMCLOUD_LOG ]; then |
| 33 | lotate $RAMCLOUD_LOG |
| 34 | fi |
| 35 | |
| 36 | # Run ramcloud |
| 37 | echo "Starting ramcloud coordinator" |
| 38 | $RAMCLOUD_DIR/obj.blueprint-java/coordinator -L $RAMCLOUD_COORDINATOR > $RAMCLOUD_LOG 2>&1 & |
| 39 | } |
| 40 | |
| 41 | function stop { |
| 42 | # Kill the existing processes |
| 43 | capid=`pgrep coordinator | awk '{print $1}'` |
| 44 | pids="$capid" |
| 45 | for p in ${pids}; do |
| 46 | if [ x$p != "x" ]; then |
| 47 | kill -KILL $p |
| 48 | echo "Killed existing prosess (pid: $p)" |
| 49 | fi |
| 50 | done |
| 51 | } |
| 52 | |
| 53 | function deldb { |
| 54 | # # Delete the berkeley db database |
| 55 | if [ -d "/tmp/ramcloud.conf" ]; then |
| 56 | echo "deleting berkeley db dir" |
| 57 | sudo rm -rf /tmp/ramcloud.conf |
| 58 | fi |
| 59 | } |
| 60 | |
| 61 | case "$1" in |
| 62 | start) |
| 63 | deldb |
| 64 | cp $ONOS_HOME/conf/ramcloud.conf /tmp |
| 65 | stop |
| 66 | start |
| 67 | ;; |
| 68 | stop) |
| 69 | stop |
| 70 | ;; |
| 71 | # deldb) |
| 72 | # deldb |
| 73 | # ;; |
| 74 | status) |
| 75 | n=`pgrep -f obj.blueprint-java/coordinator | wc -l` |
| 76 | echo "$n ramcloud coordinator is running" |
| 77 | ;; |
| 78 | *) |
| 79 | echo "Usage: $0 {start|stop|restart|status}" |
| 80 | exit 1 |
| 81 | esac |