blob: 899cd34940f586c1e3b0c9f9859eccea896b50c6 [file] [log] [blame]
Ubuntu08edc7a2013-01-30 17:59:19 +00001#!/bin/bash
2
3# Set paths
Bob Lantzc7c05402013-12-16 21:22:12 -08004ONOS_HOME="${ONOS_HOME:-`dirname $0`}"
Masayoshi Kobayashi99730902013-06-27 23:23:20 -07005
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -07006## 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 -08007ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_HOME}/logback.`hostname`.xml}
8LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
9
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070010ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
Ubuntu08edc7a2013-01-30 17:59:19 +000011PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070012LOGS="$ONOS_LOG $PCAP_LOG"
Ubuntu08edc7a2013-01-30 17:59:19 +000013
Bob Lantzf89714c2013-12-17 12:35:05 -080014ONOS_PROPS=${ONOS_PROPS:-${ONOS_HOME}/conf/onos.properties}
15JMX_PORT=${JMX_PORT:-7189}
Bob Lantzc7c05402013-12-16 21:22:12 -080016
Ubuntu08edc7a2013-01-30 17:59:19 +000017# Set JVM options
Bob Lantzc7c05402013-12-16 21:22:12 -080018JVM_OPTS="${JVM_OPTS:-}"
timlindberg8b13e702013-07-17 14:45:50 -070019## If you want JaCoCo Code Coverage reports... uncomment line below
mininet4a828f22013-12-10 14:22:39 -080020#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 -070021JVM_OPTS="$JVM_OPTS -server -d64"
Yuta HIGUCHI37f8b7d2014-01-20 09:43:19 -080022#JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070023#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
24JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
25#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070026JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Jonathan Hartf7562782013-04-03 19:50:36 -070027JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
28JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070029JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
Ubuntu08edc7a2013-01-30 17:59:19 +000030#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070031JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
32 -XX:+UseThreadPriorities \
33 -XX:ThreadPriorityPolicy=42 \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070034 -XX:+UseCompressedOops \
Bob Lantzc7c05402013-12-16 21:22:12 -080035 -Dcom.sun.management.jmxremote.port=$JMX_PORT \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070036 -Dcom.sun.management.jmxremote.ssl=false \
37 -Dcom.sun.management.jmxremote.authenticate=false"
Pavlin Radoslavova56fb322013-10-16 03:05:58 -070038JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j"
Ubuntu08edc7a2013-01-30 17:59:19 +000039
Pankaj Berdebbd38612013-06-22 05:59:12 -070040# Set ONOS core main class
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070041MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
Ubuntu08edc7a2013-01-30 17:59:19 +000042
Bob Lantz20612522013-12-17 00:30:54 -080043MVN=${MVN:-mvn -o}
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070044
Yuta HIGUCHI8d9723d2013-12-21 00:10:07 -080045if [ ! -f ${ONOS_HOME}/.javacp ]; then
46 ${MVN} -f ${ONOS_HOME}/pom.xml compile
47fi
48JAVA_CP=`cat ${ONOS_HOME}/.javacp`
49JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes"
50
admin6bdc9992013-02-06 11:06:02 -080051#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000052#<appender-ref ref="STDOUT" />
53
54function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000055 logfile=$1
56 nr_max=${2:-10}
57 if [ -f $logfile ]; then
58 for i in `seq $(expr $nr_max - 1) -1 1`; do
59 if [ -f ${logfile}.${i} ]; then
60 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
61 fi
62 done
63 mv $logfile $logfile.1
64 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000065}
66
67function start {
68 if [ ! -d ${LOGDIR} ]; then
69 mkdir -p ${LOGDIR}
70 fi
71 # Backup log files
72 for log in ${LOGS}; do
73 echo "rotate log: $log"
74 if [ -f ${log} ]; then
75 lotate ${log}
76 fi
77 done
78
Jonathan Hart0ae27772013-03-19 13:03:52 -070079# Create a logback file if required
Jonathan Hartb5ad4612013-09-27 14:47:25 +120080 if [ ! -f ${ONOS_LOGBACK} ]; then
81 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Yuta HIGUCHI51e5f302014-01-06 16:28:51 -080082<configuration scan="true" scanPeriod="1 minutes" debug="true">
Jonathan Hart0ae27772013-03-19 13:03:52 -070083<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
84<encoder>
85<pattern>%level [%logger:%thread] %msg%n</pattern>
86</encoder>
87</appender>
88
89<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070090<file>${ONOS_LOG}</file>
Jonathan Hart0ae27772013-03-19 13:03:52 -070091<encoder>
92<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
Yuta HIGUCHI51e5f302014-01-06 16:28:51 -080093<immediateFlush>true</immediateFlush>
Jonathan Hart0ae27772013-03-19 13:03:52 -070094</encoder>
95</appender>
96
97<logger name="org" level="WARN"/>
98<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
99<logger name="net.floodlightcontroller.logging" level="WARN"/>
Jonathan Hart64a036d2014-01-15 10:58:01 -0800100<logger name="com.thinkaurelius.titan" level="INFO"/>
Jonathan Hart0ae27772013-03-19 13:03:52 -0700101
102<root level="DEBUG">
103<appender-ref ref="FILE" />
104</root>
105</configuration>
106EOF_LOGBACK
Jonathan Hartb5ad4612013-09-27 14:47:25 +1200107 fi
Jonathan Hart0ae27772013-03-19 13:03:52 -0700108
Yuta HIGUCHI4fb214c2013-12-10 14:56:52 -0800109 # Run ONOS
Ubuntu08edc7a2013-01-30 17:59:19 +0000110 echo "Starting ONOS controller ..."
Bob Lantzc7c05402013-12-16 21:22:12 -0800111 echo
Jonathan Harte4997b92013-03-22 09:57:41 -0700112
Bob Lantzc7c05402013-12-16 21:22:12 -0800113 # XXX : MVN has to run at the project top dir
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700114 echo $ONOS_HOME
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -0700115 cd ${ONOS_HOME}
Bob Lantzc7c05402013-12-16 21:22:12 -0800116 pwd
Yuta HIGUCHI8d9723d2013-12-21 00:10:07 -0800117 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 -0700118
119 echo "Waiting for ONOS to start..."
120 COUNT=0
121 ESTATE=0
122 while [ "$COUNT" != "10" ]; do
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700123 echo -n "."
124 sleep 1
125# COUNT=$((COUNT + 1))
126# sleep $COUNT
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700127 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
128 if [ "$n" -ge "1" ]; then
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700129 echo ""
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700130 exit 0
131 fi
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700132 done
133 echo "Timed out"
134 exit 1
Jonathan Harte4997b92013-03-22 09:57:41 -0700135
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -0700136# 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 +0000137# 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 +0000138}
139
140function stop {
141 # Kill the existing processes
Pankaj Berde77b58512013-04-05 12:06:37 -0700142 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
Ubuntu08edc7a2013-01-30 17:59:19 +0000143 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
144 pids="$flpid $tdpid"
145 for p in ${pids}; do
146 if [ x$p != "x" ]; then
timlindberg8b13e702013-07-17 14:45:50 -0700147 kill -TERM $p
Pankaj Berdef71f6cb2013-06-27 18:30:53 -0700148 echo "Killed existing process (pid: $p)"
Ubuntu08edc7a2013-01-30 17:59:19 +0000149 fi
150 done
151}
152
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000153function check_db {
154 if [ -d "/tmp/cassandra.titan" ]; then
155 echo "Cassandra is running on local berkely db. Exitting"
156 exit
157 fi
158 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000159 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000160 echo "Cassandra is not running. Exitting"
161 exit
162 fi
163}
admin6bdc9992013-02-06 11:06:02 -0800164
Ubuntu08edc7a2013-01-30 17:59:19 +0000165case "$1" in
166 start)
167 stop
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000168 check_db
Bob Lantzc7c05402013-12-16 21:22:12 -0800169 start
170 ;;
171 startnokill)
172 check_db
173 start
Ubuntu08edc7a2013-01-30 17:59:19 +0000174 ;;
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000175 startifdown)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700176 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000177 if [ $n == 0 ]; then
178 start
Bob Lantzc7c05402013-12-16 21:22:12 -0800179 else
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000180 echo "$n instance of onos running"
181 fi
182 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000183 stop)
184 stop
185 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000186 status)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700187 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Ubuntu08edc7a2013-01-30 17:59:19 +0000188 echo "$n instance of onos running"
189 ;;
190 *)
Yuta HIGUCHI645a6682014-01-02 11:10:12 -0800191 echo "Usage: $0 {start|stop|status|startifdown}"
Ubuntu08edc7a2013-01-30 17:59:19 +0000192 exit 1
193esac