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 | |
| 5 | function host2ip (){ |
| 6 | ip=`egrep "$1\$" /etc/hosts |grep -v "ip6"| awk '{print $1}'` |
| 7 | echo $ip |
| 8 | } |
| 9 | |
| 10 | # Set paths |
| 11 | ONOS_HOME=`dirname $0` |
| 12 | RAMCLOUD_DIR=${HOME}/ramcloud |
| 13 | LOGDIR=${ONOS_HOME}/onos-logs |
| 14 | RAMCLOUD_LOG=${LOGDIR}/ramcloudcoordinator.`hostname`.log |
| 15 | thishost=`hostname` |
| 16 | thisip=`host2ip $thishost` |
| 17 | RAMCLOUD_COORDINATOR="fast+udp:host=$thisip,port=12242" |
| 18 | |
| 19 | function lotate { |
| 20 | logfile=$1 |
| 21 | nr_max=${2:-10} |
| 22 | if [ -f $logfile ]; then |
| 23 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 24 | if [ -f ${logfile}.${i} ]; then |
| 25 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 26 | fi |
| 27 | done |
| 28 | mv $logfile $logfile.1 |
| 29 | fi |
| 30 | } |
| 31 | |
| 32 | function start { |
| 33 | if [ ! -d ${LOGDIR} ]; then |
| 34 | mkdir -p ${LOGDIR} |
| 35 | fi |
| 36 | echo "rotate log: $log" |
| 37 | if [ -f $RAMCLOUD_LOG ]; then |
| 38 | lotate $RAMCLOUD_LOG |
| 39 | fi |
| 40 | |
| 41 | # Run ramcloud |
| 42 | echo "Starting ramcloud coordinator" |
| 43 | $RAMCLOUD_DIR/obj.blueprint-java/coordinator -L $RAMCLOUD_COORDINATOR > $RAMCLOUD_LOG 2>&1 & |
| 44 | } |
| 45 | |
| 46 | function stop { |
| 47 | # Kill the existing processes |
| 48 | capid=`pgrep coordinator | awk '{print $1}'` |
| 49 | pids="$capid" |
| 50 | for p in ${pids}; do |
| 51 | if [ x$p != "x" ]; then |
| 52 | kill -KILL $p |
| 53 | echo "Killed existing prosess (pid: $p)" |
| 54 | fi |
| 55 | done |
| 56 | } |
| 57 | |
| 58 | function deldb { |
| 59 | # # Delete the berkeley db database |
| 60 | if [ -d "/tmp/ramcloud.conf" ]; then |
| 61 | echo "deleting berkeley db dir" |
| 62 | sudo rm -rf /tmp/ramcloud.conf |
| 63 | fi |
| 64 | } |
| 65 | |
| 66 | case "$1" in |
| 67 | start) |
| 68 | deldb |
| 69 | cp $ONOS_HOME/conf/ramcloud.conf /tmp |
| 70 | stop |
| 71 | start |
| 72 | ;; |
| 73 | stop) |
| 74 | stop |
| 75 | ;; |
| 76 | # deldb) |
| 77 | # deldb |
| 78 | # ;; |
| 79 | status) |
| 80 | n=`pgrep -f obj.blueprint-java/coordinator | wc -l` |
| 81 | echo "$n ramcloud coordinator is running" |
| 82 | ;; |
| 83 | *) |
| 84 | echo "Usage: $0 {start|stop|restart|status}" |
| 85 | exit 1 |
| 86 | esac |