blob: bba962ab519f11c80e63b1e0ff2a5dbff94b4b33 [file] [log] [blame]
yoshi28bac132014-01-22 11:00:17 -08001#!/bin/bash
2
3export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud:${HOME}/ramcloud/obj.blueprint-java
4
5function host2ip (){
6 ip=`egrep "$1\$" /etc/hosts |grep -v "ip6"| awk '{print $1}'`
7 echo $ip
8}
9
10# Set paths
11ONOS_HOME=`dirname $0`
12RAMCLOUD_DIR=${HOME}/ramcloud
13LOGDIR=${ONOS_HOME}/onos-logs
14RAMCLOUD_LOG=${LOGDIR}/ramcloudcoordinator.`hostname`.log
15thishost=`hostname`
16thisip=`host2ip $thishost`
17RAMCLOUD_COORDINATOR="fast+udp:host=$thisip,port=12242"
18
19function 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
32function 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
46function 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
58function 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
66case "$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
86esac