yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 3 | |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 4 | # Set paths |
| 5 | ONOS_HOME=`dirname $0` |
| 6 | RAMCLOUD_DIR=${HOME}/ramcloud |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 7 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
yoshi | f280640 | 2014-01-23 09:28:39 -0800 | [diff] [blame] | 8 | RAMCLOUD_LOG=${LOGDIR}/ramcloud.coordinator.`hostname`.log |
| 9 | coordinatorip=`grep coordinatorIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 10 | coordinatorport=`grep coordinatorPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 11 | RAMCLOUD_COORDINATOR=`echo $coordinatorip","$coordinatorport` |
Yuta HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 12 | RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master} |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 13 | |
| 14 | function 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 | |
| 27 | function 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 HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 38 | $RAMCLOUD_DIR/obj.${RAMCLOUD_BRANCH}/coordinator -L $RAMCLOUD_COORDINATOR > $RAMCLOUD_LOG 2>&1 & |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | function 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 | |
| 53 | function 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 | |
| 61 | case "$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 HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 75 | n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 76 | echo "$n ramcloud coordinator is running" |
| 77 | ;; |
| 78 | *) |
| 79 | echo "Usage: $0 {start|stop|restart|status}" |
| 80 | exit 1 |
| 81 | esac |