blob: a64483755b740488f53df8881d5f97a57e63dac9 [file] [log] [blame]
onlab-qa25193a62013-12-04 13:27:38 -08001#!/bin/bash
2
yoshi391d68d2014-01-21 11:56:59 -08003ulimit -c unlimited
4export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud:${HOME}/ramcloud/obj.blueprint-java
5
onlab-qa25193a62013-12-04 13:27:38 -08006# Set paths
7ONOS_HOME=`dirname $0`
8RAMCLOUD_DIR=${HOME}/ramcloud
yoshi391d68d2014-01-21 11:56:59 -08009LOGDIR=${ONOS_HOME}/onos-logs
yoshif2806402014-01-23 09:28:39 -080010RAMCLOUD_LOG=${LOGDIR}/ramcloud.server.`hostname`.log
yoshi2c06b022014-01-23 09:09:00 -080011coordinatorip=`grep coordinatorIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
12coordinatorport=`grep coordinatorPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
yoshif2806402014-01-23 09:28:39 -080013RAMCLOUD_COORDINATOR=`echo $coordinatorip","$coordinatorport`
14serverip=`grep serverIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
15serverport=`grep serverPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
16RAMCLOUD_SERVER=`echo $serverip","$serverport`
onlab-qa25193a62013-12-04 13:27:38 -080017
18function lotate {
19 logfile=$1
20 nr_max=${2:-10}
21 if [ -f $logfile ]; then
22 for i in `seq $(expr $nr_max - 1) -1 1`; do
23 if [ -f ${logfile}.${i} ]; then
24 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
25 fi
26 done
27 mv $logfile $logfile.1
28 fi
29}
30
31function start {
32 if [ ! -d ${LOGDIR} ]; then
33 mkdir -p ${LOGDIR}
34 fi
35 echo "rotate log: $log"
36 if [ -f $RAMCLOUD_LOG ]; then
37 lotate $RAMCLOUD_LOG
38 fi
39
40 # Run ramcloud
41 echo "Starting ramcloud"
yoshi99b7dbf2014-01-22 16:30:49 -080042 $RAMCLOUD_DIR/obj.blueprint-java/server -M -L $RAMCLOUD_SERVER -C $RAMCLOUD_COORDINATOR --detectFailures 0 > $RAMCLOUD_LOG 2>&1 &
onlab-qa25193a62013-12-04 13:27:38 -080043}
44
45function stop {
46 # Kill the existing processes
yoshi391d68d2014-01-21 11:56:59 -080047 capid=`pgrep -f obj.blueprint-java/server | awk '{print $1}'`
onlab-qa25193a62013-12-04 13:27:38 -080048 pids="$capid"
49 for p in ${pids}; do
50 if [ x$p != "x" ]; then
51 kill -KILL $p
52 echo "Killed existing prosess (pid: $p)"
53 fi
54 done
55}
56
57function deldb {
58# # Delete the berkeley db database
59 if [ -d "/tmp/ramcloud.conf" ]; then
60 echo "deleting berkeley db dir"
61 sudo rm -rf /tmp/ramcloud.conf
62 fi
63}
64
65case "$1" in
66 start)
67 deldb
68 cp $ONOS_HOME/conf/ramcloud.conf /tmp
69 stop
70 start
71 ;;
72 stop)
73 stop
74 ;;
75# deldb)
76# deldb
77# ;;
78 status)
yoshi391d68d2014-01-21 11:56:59 -080079 n=`pgrep -f obj.blueprint-java/server | wc -l`
onlab-qa25193a62013-12-04 13:27:38 -080080 echo "$n ramcloud server running"
81 ;;
82 *)
83 echo "Usage: $0 {start|stop|restart|status}"
84 exit 1
85esac