blob: a1eedcdba21befdc2165292366d2e2725bffe03d [file] [log] [blame]
Ubuntu08edc7a2013-01-30 17:59:19 +00001#!/bin/bash
yoshid76fa1f2013-12-19 14:20:34 -08002ulimit -c unlimited
3export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${HOME}/ramcloud/bindings/java/edu/stanford/ramcloud:${HOME}/ramcloud/obj.blueprint-java
Ubuntu08edc7a2013-01-30 17:59:19 +00004
5# Set paths
Bob Lantzc7c05402013-12-16 21:22:12 -08006ONOS_HOME="${ONOS_HOME:-`dirname $0`}"
Masayoshi Kobayashi99730902013-06-27 23:23:20 -07007
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -07008## Because the script change dir to $ONOS_HOME, we can set ONOS_LOGBACK and LOGDIR relative to $ONOS_HOME
Bob Lantzc7c05402013-12-16 21:22:12 -08009ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_HOME}/logback.`hostname`.xml}
10LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
11
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070012ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
Ubuntu08edc7a2013-01-30 17:59:19 +000013PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070014LOGS="$ONOS_LOG $PCAP_LOG"
Ubuntu08edc7a2013-01-30 17:59:19 +000015
Bob Lantzf89714c2013-12-17 12:35:05 -080016ONOS_PROPS=${ONOS_PROPS:-${ONOS_HOME}/conf/onos.properties}
17JMX_PORT=${JMX_PORT:-7189}
Bob Lantzc7c05402013-12-16 21:22:12 -080018
Ubuntu08edc7a2013-01-30 17:59:19 +000019# Set JVM options
Bob Lantzc7c05402013-12-16 21:22:12 -080020JVM_OPTS="${JVM_OPTS:-}"
timlindberg8b13e702013-07-17 14:45:50 -070021## If you want JaCoCo Code Coverage reports... uncomment line below
mininet4a828f22013-12-10 14:22:39 -080022#JVM_OPTS="$JVM_OPTS -javaagent:${ONOS_HOME}/lib/jacocoagent.jar=dumponexit=true,output=file,destfile=${LOGDIR}/jacoco.exec"
Jonathan Hartf7562782013-04-03 19:50:36 -070023JVM_OPTS="$JVM_OPTS -server -d64"
yoshid76fa1f2013-12-19 14:20:34 -080024#JVM_OPTS="$JVM_OPTS -server -d64 -XX:+UnlockCommercialFeatures -XX:+FlightRecorder"
25JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070026#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
yoshid76fa1f2013-12-19 14:20:34 -080027#JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070028#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070029JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Jonathan Hartf7562782013-04-03 19:50:36 -070030JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
31JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070032JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
Ubuntu08edc7a2013-01-30 17:59:19 +000033#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070034JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
35 -XX:+UseThreadPriorities \
36 -XX:ThreadPriorityPolicy=42 \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070037 -XX:+UseCompressedOops \
Bob Lantzc7c05402013-12-16 21:22:12 -080038 -Dcom.sun.management.jmxremote.port=$JMX_PORT \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070039 -Dcom.sun.management.jmxremote.ssl=false \
yoshid76fa1f2013-12-19 14:20:34 -080040 -Dbenchmark.measureBP=0 \
41 -Dbenchmark.measureRc=0 \
42 -Dbenchmark.measureONOS=0 \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070043 -Dcom.sun.management.jmxremote.authenticate=false"
Pavlin Radoslavova56fb322013-10-16 03:05:58 -070044JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j"
Ubuntu08edc7a2013-01-30 17:59:19 +000045
Pankaj Berdebbd38612013-06-22 05:59:12 -070046# Set ONOS core main class
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070047MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
Ubuntu08edc7a2013-01-30 17:59:19 +000048
Bob Lantz20612522013-12-17 00:30:54 -080049MVN=${MVN:-mvn -o}
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070050
Yuta HIGUCHIb561efa2013-12-20 01:35:04 -080051if [ ! -f ${ONOS_HOME}/.javacp ]; then
52 ${MVN} -f ${ONOS_HOME}/pom.xml compile
53fi
54JAVA_CP=`cat ${ONOS_HOME}/.javacp`
Yuta HIGUCHI6e4eca52013-12-20 09:12:20 -080055JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes"
Yuta HIGUCHIb561efa2013-12-20 01:35:04 -080056
admin6bdc9992013-02-06 11:06:02 -080057#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000058#<appender-ref ref="STDOUT" />
59
60function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000061 logfile=$1
62 nr_max=${2:-10}
63 if [ -f $logfile ]; then
64 for i in `seq $(expr $nr_max - 1) -1 1`; do
65 if [ -f ${logfile}.${i} ]; then
66 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
67 fi
68 done
69 mv $logfile $logfile.1
70 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000071}
72
73function start {
74 if [ ! -d ${LOGDIR} ]; then
75 mkdir -p ${LOGDIR}
76 fi
77 # Backup log files
78 for log in ${LOGS}; do
79 echo "rotate log: $log"
80 if [ -f ${log} ]; then
81 lotate ${log}
82 fi
83 done
84
Jonathan Hart0ae27772013-03-19 13:03:52 -070085# Create a logback file if required
Jonathan Hartb5ad4612013-09-27 14:47:25 +120086 if [ ! -f ${ONOS_LOGBACK} ]; then
87 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Yuta HIGUCHI51e5f302014-01-06 16:28:51 -080088<configuration scan="true" scanPeriod="1 minutes" debug="true">
Jonathan Hart0ae27772013-03-19 13:03:52 -070089<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
90<encoder>
91<pattern>%level [%logger:%thread] %msg%n</pattern>
92</encoder>
93</appender>
94
95<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070096<file>${ONOS_LOG}</file>
Jonathan Hart0ae27772013-03-19 13:03:52 -070097<encoder>
98<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
Yuta HIGUCHI51e5f302014-01-06 16:28:51 -080099<immediateFlush>true</immediateFlush>
Jonathan Hart0ae27772013-03-19 13:03:52 -0700100</encoder>
101</appender>
102
103<logger name="org" level="WARN"/>
104<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
105<logger name="net.floodlightcontroller.logging" level="WARN"/>
106
107<root level="DEBUG">
108<appender-ref ref="FILE" />
109</root>
110</configuration>
111EOF_LOGBACK
Jonathan Hartb5ad4612013-09-27 14:47:25 +1200112 fi
Jonathan Hart0ae27772013-03-19 13:03:52 -0700113
Yuta HIGUCHI4fb214c2013-12-10 14:56:52 -0800114 # Run ONOS
Ubuntu08edc7a2013-01-30 17:59:19 +0000115 echo "Starting ONOS controller ..."
Bob Lantzc7c05402013-12-16 21:22:12 -0800116 echo
Jonathan Harte4997b92013-03-22 09:57:41 -0700117
Bob Lantzc7c05402013-12-16 21:22:12 -0800118 # XXX : MVN has to run at the project top dir
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700119 echo $ONOS_HOME
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -0700120 cd ${ONOS_HOME}
Bob Lantzc7c05402013-12-16 21:22:12 -0800121 pwd
122 echo "${MVN} exec:exec -Dexec.executable=\"java\" -Dexec.args=\"${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_PROPS}\""
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700123
Yuta HIGUCHIb561efa2013-12-20 01:35:04 -0800124 #${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_PROPS}" > ${LOGDIR}/onos.`hostname`.stdout 2>${LOGDIR}/onos.`hostname`.stderr &
125 java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/onos.`hostname`.stdout 2>${LOGDIR}/onos.`hostname`.stderr &
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700126
127 echo "Waiting for ONOS to start..."
128 COUNT=0
129 ESTATE=0
130 while [ "$COUNT" != "10" ]; do
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700131 echo -n "."
132 sleep 1
133# COUNT=$((COUNT + 1))
134# sleep $COUNT
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700135 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
136 if [ "$n" -ge "1" ]; then
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700137 echo ""
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700138 exit 0
139 fi
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700140 done
141 echo "Timed out"
142 exit 1
Jonathan Harte4997b92013-03-22 09:57:41 -0700143
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -0700144# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
Masayoshi Kobayashi8849a662013-03-14 22:18:51 +0000145# sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1
Ubuntu08edc7a2013-01-30 17:59:19 +0000146}
147
148function stop {
149 # Kill the existing processes
Pankaj Berde77b58512013-04-05 12:06:37 -0700150 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
Ubuntu08edc7a2013-01-30 17:59:19 +0000151 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
152 pids="$flpid $tdpid"
153 for p in ${pids}; do
154 if [ x$p != "x" ]; then
timlindberg8b13e702013-07-17 14:45:50 -0700155 kill -TERM $p
Pankaj Berdef71f6cb2013-06-27 18:30:53 -0700156 echo "Killed existing process (pid: $p)"
Ubuntu08edc7a2013-01-30 17:59:19 +0000157 fi
158 done
159}
160
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000161function check_db {
162 if [ -d "/tmp/cassandra.titan" ]; then
163 echo "Cassandra is running on local berkely db. Exitting"
164 exit
165 fi
166 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000167 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000168 echo "Cassandra is not running. Exitting"
169 exit
170 fi
171}
admin6bdc9992013-02-06 11:06:02 -0800172
Ubuntu08edc7a2013-01-30 17:59:19 +0000173case "$1" in
174 start)
175 stop
yoshid76fa1f2013-12-19 14:20:34 -0800176# check_db
Bob Lantzc7c05402013-12-16 21:22:12 -0800177 start
178 ;;
179 startnokill)
180 check_db
181 start
Ubuntu08edc7a2013-01-30 17:59:19 +0000182 ;;
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000183 startifdown)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700184 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000185 if [ $n == 0 ]; then
186 start
Bob Lantzc7c05402013-12-16 21:22:12 -0800187 else
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000188 echo "$n instance of onos running"
189 fi
190 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000191 stop)
192 stop
193 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000194 status)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700195 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Ubuntu08edc7a2013-01-30 17:59:19 +0000196 echo "$n instance of onos running"
197 ;;
198 *)
Yuta HIGUCHI645a6682014-01-02 11:10:12 -0800199 echo "Usage: $0 {start|stop|status|startifdown}"
Ubuntu08edc7a2013-01-30 17:59:19 +0000200 exit 1
201esac