blob: fd1ec830aeb18988428b2bb95adfc4bf4137ab1b [file] [log] [blame]
yoshi28bac132014-01-22 11:00:17 -08001#!/bin/bash
2
yoshi28bac132014-01-22 11:00:17 -08003
yoshi28bac132014-01-22 11:00:17 -08004# Set paths
5ONOS_HOME=`dirname $0`
6RAMCLOUD_DIR=${HOME}/ramcloud
Bob Lantz63bbe4c2014-02-06 19:29:55 -08007LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
yoshif2806402014-01-23 09:28:39 -08008RAMCLOUD_LOG=${LOGDIR}/ramcloud.coordinator.`hostname`.log
9coordinatorip=`grep coordinatorIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
10coordinatorport=`grep coordinatorPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
11RAMCLOUD_COORDINATOR=`echo $coordinatorip","$coordinatorport`
Yuta HIGUCHIa7ec0732014-03-10 16:01:06 -070012RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master}
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"
Yuta HIGUCHIa7ec0732014-03-10 16:01:06 -070038 $RAMCLOUD_DIR/obj.${RAMCLOUD_BRANCH}/coordinator -L $RAMCLOUD_COORDINATOR > $RAMCLOUD_LOG 2>&1 &
yoshi28bac132014-01-22 11:00:17 -080039}
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)
Yuta HIGUCHIa7ec0732014-03-10 16:01:06 -070075 n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l`
yoshi28bac132014-01-22 11:00:17 -080076 echo "$n ramcloud coordinator is running"
77 ;;
78 *)
79 echo "Usage: $0 {start|stop|restart|status}"
80 exit 1
81esac