blob: 6a4232ef24c270515a01b3a5ed2a060f223654df [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
yoshi28bac132014-01-22 11:00:17 -08005# Set paths
6ONOS_HOME=`dirname $0`
7RAMCLOUD_DIR=${HOME}/ramcloud
8LOGDIR=${ONOS_HOME}/onos-logs
yoshif2806402014-01-23 09:28:39 -08009RAMCLOUD_LOG=${LOGDIR}/ramcloud.coordinator.`hostname`.log
10coordinatorip=`grep coordinatorIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
11coordinatorport=`grep coordinatorPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
12RAMCLOUD_COORDINATOR=`echo $coordinatorip","$coordinatorport`
yoshi28bac132014-01-22 11:00:17 -080013
14function 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
27function 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
41function 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
53function 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
61case "$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
81esac