onlab-qa | 25193a6 | 2013-12-04 13:27:38 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
yoshi | 391d68d | 2014-01-21 11:56:59 -0800 | [diff] [blame] | 3 | ulimit -c unlimited |
| 4 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud:${HOME}/ramcloud/obj.blueprint-java |
| 5 | |
onlab-qa | 25193a6 | 2013-12-04 13:27:38 -0800 | [diff] [blame] | 6 | # Set paths |
| 7 | ONOS_HOME=`dirname $0` |
| 8 | RAMCLOUD_DIR=${HOME}/ramcloud |
yoshi | 391d68d | 2014-01-21 11:56:59 -0800 | [diff] [blame] | 9 | LOGDIR=${ONOS_HOME}/onos-logs |
yoshi | f280640 | 2014-01-23 09:28:39 -0800 | [diff] [blame] | 10 | RAMCLOUD_LOG=${LOGDIR}/ramcloud.server.`hostname`.log |
yoshi | 2c06b02 | 2014-01-23 09:09:00 -0800 | [diff] [blame] | 11 | coordinatorip=`grep coordinatorIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 12 | coordinatorport=`grep coordinatorPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
yoshi | f280640 | 2014-01-23 09:28:39 -0800 | [diff] [blame] | 13 | RAMCLOUD_COORDINATOR=`echo $coordinatorip","$coordinatorport` |
| 14 | serverip=`grep serverIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 15 | serverport=`grep serverPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 16 | RAMCLOUD_SERVER=`echo $serverip","$serverport` |
onlab-qa | 25193a6 | 2013-12-04 13:27:38 -0800 | [diff] [blame] | 17 | |
| 18 | function 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 | |
| 31 | function 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" |
yoshi | 99b7dbf | 2014-01-22 16:30:49 -0800 | [diff] [blame] | 42 | $RAMCLOUD_DIR/obj.blueprint-java/server -M -L $RAMCLOUD_SERVER -C $RAMCLOUD_COORDINATOR --detectFailures 0 > $RAMCLOUD_LOG 2>&1 & |
onlab-qa | 25193a6 | 2013-12-04 13:27:38 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | function stop { |
| 46 | # Kill the existing processes |
yoshi | 391d68d | 2014-01-21 11:56:59 -0800 | [diff] [blame] | 47 | capid=`pgrep -f obj.blueprint-java/server | awk '{print $1}'` |
onlab-qa | 25193a6 | 2013-12-04 13:27:38 -0800 | [diff] [blame] | 48 | 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 | |
| 57 | function 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 | |
| 65 | case "$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) |
yoshi | 391d68d | 2014-01-21 11:56:59 -0800 | [diff] [blame] | 79 | n=`pgrep -f obj.blueprint-java/server | wc -l` |
onlab-qa | 25193a6 | 2013-12-04 13:27:38 -0800 | [diff] [blame] | 80 | echo "$n ramcloud server running" |
| 81 | ;; |
| 82 | *) |
| 83 | echo "Usage: $0 {start|stop|restart|status}" |
| 84 | exit 1 |
| 85 | esac |