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 |
yoshi | 391d68d | 2014-01-21 11:56:59 -0800 | [diff] [blame] | 4 | |
onlab-qa | 25193a6 | 2013-12-04 13:27:38 -0800 | [diff] [blame] | 5 | # Set paths |
| 6 | ONOS_HOME=`dirname $0` |
| 7 | RAMCLOUD_DIR=${HOME}/ramcloud |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 8 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
yoshi | f280640 | 2014-01-23 09:28:39 -0800 | [diff] [blame] | 9 | RAMCLOUD_LOG=${LOGDIR}/ramcloud.server.`hostname`.log |
yoshi | 2c06b02 | 2014-01-23 09:09:00 -0800 | [diff] [blame] | 10 | coordinatorip=`grep coordinatorIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 11 | coordinatorport=`grep coordinatorPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
yoshi | f280640 | 2014-01-23 09:28:39 -0800 | [diff] [blame] | 12 | RAMCLOUD_COORDINATOR=`echo $coordinatorip","$coordinatorport` |
| 13 | serverip=`grep serverIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 14 | serverport=`grep serverPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 15 | RAMCLOUD_SERVER=`echo $serverip","$serverport` |
Yuta HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 16 | RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master} |
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 | |
Yuta HIGUCHI | 43ab5c6 | 2014-02-25 15:11:25 -0800 | [diff] [blame] | 40 | # Run ramcloud |
onlab-qa | 25193a6 | 2013-12-04 13:27:38 -0800 | [diff] [blame] | 41 | echo "Starting ramcloud" |
Yuta HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 42 | $RAMCLOUD_DIR/obj.${RAMCLOUD_BRANCH}/server -M -L $RAMCLOUD_SERVER -C $RAMCLOUD_COORDINATOR --masterServiceThreads 1 --logCleanerThreads 1 --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 |
Yuta HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 47 | capid=`pgrep -f obj.${RAMCLOUD_BRANCH}/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) |
Yuta HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 79 | n=`pgrep -f obj.${RAMCLOUD_BRANCH}/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 |