blob: e664d0964486e7c01d1693e3f9f2521ac01947a3 [file] [log] [blame]
Ubuntu08edc7a2013-01-30 17:59:19 +00001#!/bin/bash
Yuta HIGUCHIa7ec0732014-03-10 16:01:06 -07002
yoshid76fa1f2013-12-19 14:20:34 -08003ulimit -c unlimited
Ubuntu08edc7a2013-01-30 17:59:19 +00004
5# Set paths
Bob Lantzc7c05402013-12-16 21:22:12 -08006ONOS_HOME="${ONOS_HOME:-`dirname $0`}"
Yuta HIGUCHIa7ec0732014-03-10 16:01:06 -07007RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud}
8RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master}
9
10export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${ONOS_HOME}/lib:${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}
Masayoshi Kobayashi99730902013-06-27 23:23:20 -070011
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -070012## 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 -080013ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_HOME}/logback.`hostname`.xml}
14LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
Bob Lantz63bbe4c2014-02-06 19:29:55 -080015LOGBASE=${ONOS_LOGBASE:-onos.`hostname`}
16ONOS_LOG="${LOGDIR}/${LOGBASE}.log"
17PCAP_LOG="${LOGDIR}/${LOGBASE}.pcap"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070018LOGS="$ONOS_LOG $PCAP_LOG"
Ubuntu08edc7a2013-01-30 17:59:19 +000019
Bob Lantzf89714c2013-12-17 12:35:05 -080020ONOS_PROPS=${ONOS_PROPS:-${ONOS_HOME}/conf/onos.properties}
21JMX_PORT=${JMX_PORT:-7189}
Bob Lantzc7c05402013-12-16 21:22:12 -080022
Ubuntu08edc7a2013-01-30 17:59:19 +000023# Set JVM options
Bob Lantzc7c05402013-12-16 21:22:12 -080024JVM_OPTS="${JVM_OPTS:-}"
timlindberg8b13e702013-07-17 14:45:50 -070025## If you want JaCoCo Code Coverage reports... uncomment line below
mininet4a828f22013-12-10 14:22:39 -080026#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 -070027JVM_OPTS="$JVM_OPTS -server -d64"
Yuta HIGUCHI37f8b7d2014-01-20 09:43:19 -080028#JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m"
yoshid76fa1f2013-12-19 14:20:34 -080029JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070030#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
yoshid76fa1f2013-12-19 14:20:34 -080031#JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070032#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070033JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Jonathan Hartf7562782013-04-03 19:50:36 -070034JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
35JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070036JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
Ubuntu08edc7a2013-01-30 17:59:19 +000037#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070038JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
39 -XX:+UseThreadPriorities \
40 -XX:ThreadPriorityPolicy=42 \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070041 -XX:+UseCompressedOops \
Bob Lantzc7c05402013-12-16 21:22:12 -080042 -Dcom.sun.management.jmxremote.port=$JMX_PORT \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070043 -Dcom.sun.management.jmxremote.ssl=false \
yoshid76fa1f2013-12-19 14:20:34 -080044 -Dbenchmark.measureBP=0 \
45 -Dbenchmark.measureRc=0 \
46 -Dbenchmark.measureONOS=0 \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070047 -Dcom.sun.management.jmxremote.authenticate=false"
Pavlin Radoslavova56fb322013-10-16 03:05:58 -070048JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j"
Ubuntu08edc7a2013-01-30 17:59:19 +000049
Pankaj Berdebbd38612013-06-22 05:59:12 -070050# Set ONOS core main class
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070051MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
Ubuntu08edc7a2013-01-30 17:59:19 +000052
Bob Lantz20612522013-12-17 00:30:54 -080053MVN=${MVN:-mvn -o}
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070054
Yuta HIGUCHIfbd9a7e2014-03-23 00:18:50 -070055CPFILE=${ONOS_HOME}/.javacp.`hostname`
56if [ ! -f ${CPFILE} ]; then
Yuta HIGUCHIb561efa2013-12-20 01:35:04 -080057 ${MVN} -f ${ONOS_HOME}/pom.xml compile
58fi
Yuta HIGUCHIfbd9a7e2014-03-23 00:18:50 -070059JAVA_CP=`cat ${CPFILE}`
Yuta HIGUCHI6e4eca52013-12-20 09:12:20 -080060JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes"
Yuta HIGUCHIb561efa2013-12-20 01:35:04 -080061
admin6bdc9992013-02-06 11:06:02 -080062#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000063#<appender-ref ref="STDOUT" />
64
65function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000066 logfile=$1
67 nr_max=${2:-10}
68 if [ -f $logfile ]; then
69 for i in `seq $(expr $nr_max - 1) -1 1`; do
70 if [ -f ${logfile}.${i} ]; then
71 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
72 fi
73 done
74 mv $logfile $logfile.1
75 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000076}
77
78function start {
79 if [ ! -d ${LOGDIR} ]; then
80 mkdir -p ${LOGDIR}
81 fi
82 # Backup log files
83 for log in ${LOGS}; do
84 echo "rotate log: $log"
85 if [ -f ${log} ]; then
86 lotate ${log}
87 fi
88 done
89
Jonathan Hart0ae27772013-03-19 13:03:52 -070090# Create a logback file if required
Jonathan Hartb5ad4612013-09-27 14:47:25 +120091 if [ ! -f ${ONOS_LOGBACK} ]; then
92 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Yuta HIGUCHI51e5f302014-01-06 16:28:51 -080093<configuration scan="true" scanPeriod="1 minutes" debug="true">
Jonathan Hart0ae27772013-03-19 13:03:52 -070094<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
95<encoder>
96<pattern>%level [%logger:%thread] %msg%n</pattern>
97</encoder>
98</appender>
99
100<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -0700101<file>${ONOS_LOG}</file>
Jonathan Hart0ae27772013-03-19 13:03:52 -0700102<encoder>
103<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
Yuta HIGUCHI51e5f302014-01-06 16:28:51 -0800104<immediateFlush>true</immediateFlush>
Jonathan Hart0ae27772013-03-19 13:03:52 -0700105</encoder>
106</appender>
107
108<logger name="org" level="WARN"/>
109<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
110<logger name="net.floodlightcontroller.logging" level="WARN"/>
Jonathan Hart64a036d2014-01-15 10:58:01 -0800111<logger name="com.thinkaurelius.titan" level="INFO"/>
Jonathan Hart0ae27772013-03-19 13:03:52 -0700112
113<root level="DEBUG">
114<appender-ref ref="FILE" />
115</root>
116</configuration>
117EOF_LOGBACK
Jonathan Hartb5ad4612013-09-27 14:47:25 +1200118 fi
Jonathan Hart0ae27772013-03-19 13:03:52 -0700119
Yuta HIGUCHI4fb214c2013-12-10 14:56:52 -0800120 # Run ONOS
Ubuntu08edc7a2013-01-30 17:59:19 +0000121 echo "Starting ONOS controller ..."
Bob Lantzc7c05402013-12-16 21:22:12 -0800122 echo
Jonathan Harte4997b92013-03-22 09:57:41 -0700123
Bob Lantzc7c05402013-12-16 21:22:12 -0800124 # XXX : MVN has to run at the project top dir
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700125 echo $ONOS_HOME
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -0700126 cd ${ONOS_HOME}
Bob Lantzc7c05402013-12-16 21:22:12 -0800127 pwd
Bob Lantz63bbe4c2014-02-06 19:29:55 -0800128 java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr &
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700129
130 echo "Waiting for ONOS to start..."
131 COUNT=0
132 ESTATE=0
133 while [ "$COUNT" != "10" ]; do
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700134 echo -n "."
135 sleep 1
136# COUNT=$((COUNT + 1))
137# sleep $COUNT
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700138 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
139 if [ "$n" -ge "1" ]; then
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700140 echo ""
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700141 exit 0
142 fi
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700143 done
144 echo "Timed out"
145 exit 1
Jonathan Harte4997b92013-03-22 09:57:41 -0700146
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -0700147# 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 +0000148# 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 +0000149}
150
151function stop {
152 # Kill the existing processes
Pankaj Berde77b58512013-04-05 12:06:37 -0700153 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
Ubuntu08edc7a2013-01-30 17:59:19 +0000154 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
155 pids="$flpid $tdpid"
156 for p in ${pids}; do
157 if [ x$p != "x" ]; then
timlindberg8b13e702013-07-17 14:45:50 -0700158 kill -TERM $p
Pankaj Berdef71f6cb2013-06-27 18:30:53 -0700159 echo "Killed existing process (pid: $p)"
Ubuntu08edc7a2013-01-30 17:59:19 +0000160 fi
161 done
162}
163
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000164function check_db {
165 if [ -d "/tmp/cassandra.titan" ]; then
166 echo "Cassandra is running on local berkely db. Exitting"
167 exit
168 fi
169 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000170 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000171 echo "Cassandra is not running. Exitting"
172 exit
173 fi
174}
admin6bdc9992013-02-06 11:06:02 -0800175
Ubuntu08edc7a2013-01-30 17:59:19 +0000176case "$1" in
177 start)
178 stop
yoshid76fa1f2013-12-19 14:20:34 -0800179# check_db
Bob Lantzc7c05402013-12-16 21:22:12 -0800180 start
181 ;;
182 startnokill)
Bob Lantz63bbe4c2014-02-06 19:29:55 -0800183# check_db
Bob Lantzc7c05402013-12-16 21:22:12 -0800184 start
Ubuntu08edc7a2013-01-30 17:59:19 +0000185 ;;
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000186 startifdown)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700187 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000188 if [ $n == 0 ]; then
189 start
Bob Lantzc7c05402013-12-16 21:22:12 -0800190 else
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000191 echo "$n instance of onos running"
192 fi
193 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000194 stop)
195 stop
196 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000197 status)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700198 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Ubuntu08edc7a2013-01-30 17:59:19 +0000199 echo "$n instance of onos running"
200 ;;
201 *)
Yuta HIGUCHI645a6682014-01-02 11:10:12 -0800202 echo "Usage: $0 {start|stop|status|startifdown}"
Ubuntu08edc7a2013-01-30 17:59:19 +0000203 exit 1
204esac