yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 3 | echo |
| 4 | echo "========================================================================" |
| 5 | echo "[WARNING] This script is deprecated. Use \"\$ ./onos.sh rc-coord\" instead." |
| 6 | echo "========================================================================" |
| 7 | echo |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 8 | |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 9 | # Set paths |
| 10 | ONOS_HOME=`dirname $0` |
| 11 | RAMCLOUD_DIR=${HOME}/ramcloud |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 12 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
yoshi | f280640 | 2014-01-23 09:28:39 -0800 | [diff] [blame] | 13 | RAMCLOUD_LOG=${LOGDIR}/ramcloud.coordinator.`hostname`.log |
Jonathan Hart | d724145 | 2014-03-20 16:45:35 -0700 | [diff] [blame] | 14 | RAMCLOUD_CONF=${RAMCLOUD_CONF:-${ONOS_HOME}/conf/ramcloud.conf} |
| 15 | #coordinatorip=`grep coordinatorIp ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 16 | #coordinatorport=`grep coordinatorPort ${ONOS_HOME}/conf/ramcloud.conf | cut -d "=" -f 2,3` |
| 17 | |
| 18 | COORDINATOR_IP=`grep coordinatorIp ${RAMCLOUD_CONF} | cut -d "=" -f 2,3` |
| 19 | COORDINATOR_PORT=`grep coordinatorPort ${RAMCLOUD_CONF} | cut -d "=" -f 2,3` |
| 20 | |
| 21 | #RAMCLOUD_COORDINATOR=`echo $coordinatorip","$coordinatorport` |
| 22 | RAMCLOUD_COORDINATOR=`echo $COORDINATOR_IP","$COORDINATOR_PORT` |
Yuta HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 23 | RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master} |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 24 | |
| 25 | function lotate { |
| 26 | logfile=$1 |
| 27 | nr_max=${2:-10} |
| 28 | if [ -f $logfile ]; then |
| 29 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 30 | if [ -f ${logfile}.${i} ]; then |
| 31 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 32 | fi |
| 33 | done |
| 34 | mv $logfile $logfile.1 |
| 35 | fi |
| 36 | } |
| 37 | |
| 38 | function start { |
| 39 | if [ ! -d ${LOGDIR} ]; then |
| 40 | mkdir -p ${LOGDIR} |
| 41 | fi |
| 42 | echo "rotate log: $log" |
| 43 | if [ -f $RAMCLOUD_LOG ]; then |
| 44 | lotate $RAMCLOUD_LOG |
| 45 | fi |
| 46 | |
| 47 | # Run ramcloud |
| 48 | echo "Starting ramcloud coordinator" |
Yuta HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 49 | $RAMCLOUD_DIR/obj.${RAMCLOUD_BRANCH}/coordinator -L $RAMCLOUD_COORDINATOR > $RAMCLOUD_LOG 2>&1 & |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | function stop { |
| 53 | # Kill the existing processes |
| 54 | capid=`pgrep coordinator | awk '{print $1}'` |
| 55 | pids="$capid" |
| 56 | for p in ${pids}; do |
| 57 | if [ x$p != "x" ]; then |
| 58 | kill -KILL $p |
Jonathan Hart | d724145 | 2014-03-20 16:45:35 -0700 | [diff] [blame] | 59 | echo "Killed existing process (pid: $p)" |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 60 | fi |
| 61 | done |
| 62 | } |
| 63 | |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 64 | case "$1" in |
| 65 | start) |
Jonathan Hart | d724145 | 2014-03-20 16:45:35 -0700 | [diff] [blame] | 66 | #cp $ONOS_HOME/conf/ramcloud.conf /tmp |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 67 | stop |
| 68 | start |
| 69 | ;; |
| 70 | stop) |
| 71 | stop |
| 72 | ;; |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 73 | status) |
Yuta HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 74 | n=`pgrep -f obj.${RAMCLOUD_BRANCH}/coordinator | wc -l` |
yoshi | 28bac13 | 2014-01-22 11:00:17 -0800 | [diff] [blame] | 75 | echo "$n ramcloud coordinator is running" |
| 76 | ;; |
| 77 | *) |
| 78 | echo "Usage: $0 {start|stop|restart|status}" |
| 79 | exit 1 |
| 80 | esac |