blob: 939543a649552c039414409b9b6012659377838e [file] [log] [blame]
onlab-qa25193a62013-12-04 13:27:38 -08001#!/bin/bash
2
yoshi391d68d2014-01-21 11:56:59 -08003ulimit -c unlimited
yoshi391d68d2014-01-21 11:56:59 -08004
onlab-qa25193a62013-12-04 13:27:38 -08005# Set paths
6ONOS_HOME=`dirname $0`
7RAMCLOUD_DIR=${HOME}/ramcloud
Bob Lantz63bbe4c2014-02-06 19:29:55 -08008LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
yoshif2806402014-01-23 09:28:39 -08009RAMCLOUD_LOG=${LOGDIR}/ramcloud.server.`hostname`.log
yoshi2c06b022014-01-23 09:09:00 -080010coordinatorip=`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`
yoshif2806402014-01-23 09:28:39 -080012RAMCLOUD_COORDINATOR=`echo $coordinatorip","$coordinatorport`
13serverip=`grep serverIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
14serverport=`grep serverPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3`
15RAMCLOUD_SERVER=`echo $serverip","$serverport`
Yuta HIGUCHIa7ec0732014-03-10 16:01:06 -070016RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master}
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
Yuta HIGUCHI43ab5c62014-02-25 15:11:25 -080040 # Run ramcloud
onlab-qa25193a62013-12-04 13:27:38 -080041 echo "Starting ramcloud"
Yuta HIGUCHIa7ec0732014-03-10 16:01:06 -070042 $RAMCLOUD_DIR/obj.${RAMCLOUD_BRANCH}/server -M -L $RAMCLOUD_SERVER -C $RAMCLOUD_COORDINATOR --masterServiceThreads 1 --logCleanerThreads 1 --detectFailures 0 > $RAMCLOUD_LOG 2>&1 &
onlab-qa25193a62013-12-04 13:27:38 -080043}
44
45function stop {
46 # Kill the existing processes
Yuta HIGUCHIa7ec0732014-03-10 16:01:06 -070047 capid=`pgrep -f obj.${RAMCLOUD_BRANCH}/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)
Yuta HIGUCHIa7ec0732014-03-10 16:01:06 -070079 n=`pgrep -f obj.${RAMCLOUD_BRANCH}/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