blob: 7bd0b97fee603fe0bdbefe5d372578a46608099c [file] [log] [blame]
Pankaj Berde1b399bb2013-06-12 11:04:11 -07001#!/bin/bash
2
3# Set paths
Pankaj Berdebbd38612013-06-22 05:59:12 -07004if [ -z "${ONOS_HOME}" ]; then
5 ONOS_HOME=`dirname $0`
6fi
Naoki Shiota6e44b372013-10-14 14:33:58 -07007ONOS_LOGBACK="${ONOS_HOME}/logback.`hostname`.xml"
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -07008LOGDIR=${ONOS_HOME}/onos-logs
9ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
Pankaj Berde1b399bb2013-06-12 11:04:11 -070010PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap"
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070011LOGS="$ONOS_LOG $PCAP_LOG"
Pankaj Berde1b399bb2013-06-12 11:04:11 -070012
13# Set JVM options
14JVM_OPTS=""
15JVM_OPTS="$JVM_OPTS -server -d64"
16JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070017#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
18JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Pankaj Berde1b399bb2013-06-12 11:04:11 -070019JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
mininet4a828f22013-12-10 14:22:39 -080020JVM_OPTS="$JVM_OPTS -javaagent:$ONOS_HOME/lib/jamm-0.2.5.jar"
Pankaj Berde1b399bb2013-06-12 11:04:11 -070021JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
Pankaj Berdeff1fe032013-06-27 14:59:00 -070022 -XX:+UseThreadPriorities \
23 -XX:ThreadPriorityPolicy=42 \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070024 -XX:+UseCompressedOops \
Pankaj Berdeff1fe032013-06-27 14:59:00 -070025 -Dcassandra.compaction.priority=1 \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070026 -Dcom.sun.management.jmxremote.port=7199 \
27 -Dcom.sun.management.jmxremote.ssl=false \
28 -Dcom.sun.management.jmxremote.authenticate=false"
Pavlin Radoslavov579983b2013-10-15 08:58:24 -070029JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j"
Pankaj Berde1b399bb2013-06-12 11:04:11 -070030
31#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
32
Pankaj Berdebbd38612013-06-22 05:59:12 -070033# Set Main class to start ONOS core
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070034MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
Pankaj Berde1b399bb2013-06-12 11:04:11 -070035
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070036if [ -z "${MVN}" ]; then
37 MVN="mvn"
38fi
Yuta HIGUCHI8d9723d2013-12-21 00:10:07 -080039
40if [ ! -f ${ONOS_HOME}/.javacp ]; then
41 ${MVN} -f ${ONOS_HOME}/pom.xml compile
42fi
43JAVA_CP=`cat ${ONOS_HOME}/.javacp`
44JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes"
45
Pankaj Berde1b399bb2013-06-12 11:04:11 -070046#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
47#<appender-ref ref="STDOUT" />
48
49function lotate {
50 logfile=$1
51 nr_max=${2:-10}
52 if [ -f $logfile ]; then
53 for i in `seq $(expr $nr_max - 1) -1 1`; do
54 if [ -f ${logfile}.${i} ]; then
55 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
56 fi
57 done
58 mv $logfile $logfile.1
59 fi
60}
61
62function start {
63 if [ ! -d ${LOGDIR} ]; then
64 mkdir -p ${LOGDIR}
65 fi
66 # Backup log files
67 for log in ${LOGS}; do
68 echo "rotate log: $log"
69 if [ -f ${log} ]; then
70 lotate ${log}
71 fi
72 done
73
74# Create a logback file if required
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070075 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Yuta HIGUCHI51e5f302014-01-06 16:28:51 -080076<configuration scan="true" scanPeriod="1 minutes" debug="true">
Pankaj Berde1b399bb2013-06-12 11:04:11 -070077<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
78<encoder>
79<pattern>%level [%logger:%thread] %msg%n</pattern>
80</encoder>
81</appender>
82
83<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070084<file>${ONOS_LOG}</file>
Pankaj Berde1b399bb2013-06-12 11:04:11 -070085<encoder>
86<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
Yuta HIGUCHI51e5f302014-01-06 16:28:51 -080087<immediateFlush>true</immediateFlush>
Pankaj Berde1b399bb2013-06-12 11:04:11 -070088</encoder>
89</appender>
90
91<logger name="org" level="WARN"/>
92<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
93<logger name="net.floodlightcontroller.logging" level="WARN"/>
Jonathan Hart64a036d2014-01-15 10:58:01 -080094<logger name="com.thinkaurelius.titan" level="INFO"/>
Pankaj Berde1b399bb2013-06-12 11:04:11 -070095
96<root level="DEBUG">
97<appender-ref ref="FILE" />
98</root>
99</configuration>
100EOF_LOGBACK
101
Yuta HIGUCHI4fb214c2013-12-10 14:56:52 -0800102 # Run ONOS
Pankaj Berde1b399bb2013-06-12 11:04:11 -0700103 echo "Starting ONOS controller ..."
104 echo
Pankaj Berde1b399bb2013-06-12 11:04:11 -0700105
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -0700106 # XXX MVN has to run at the project top dir..
107 cd ${ONOS_HOME}
Pavlin Radoslavov678c53d2014-01-03 18:15:30 -0800108 java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos-embedded.properties > ${LOGDIR}/onos.`hostname`.stdout 2>${LOGDIR}/onos.`hostname`.stderr &
Pankaj Berde1b399bb2013-06-12 11:04:11 -0700109
110 echo "Waiting for ONOS to start..."
111 COUNT=0
112 ESTATE=0
113 while [ "$COUNT" != "10" ]; do
114 COUNT=$((COUNT + 1))
115 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
116 if [ "$n" -ge "1" ]; then
117 exit 0
118 fi
119 sleep $COUNT
120 done
121 echo "Timed out"
122 exit 1
123
Pankaj Berdebbd38612013-06-22 05:59:12 -0700124 sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1
Pankaj Berde1b399bb2013-06-12 11:04:11 -0700125}
126
127function stop {
128 # Kill the existing processes
129 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
130 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
131 pids="$flpid $tdpid"
132 for p in ${pids}; do
133 if [ x$p != "x" ]; then
134 kill -KILL $p
Pankaj Berdebbd38612013-06-22 05:59:12 -0700135 echo "Killed existing process (pid: $p)"
Pankaj Berde1b399bb2013-06-12 11:04:11 -0700136 fi
137 done
138}
139
140function deldb {
141 # Delete the cassandra data
142 if [ -d "/tmp/cassandra" ]; then
143 rm -rf /tmp/cassandra/*
144 fi
145}
146
147case "$1" in
148 start)
149 stop
150 start
151 ;;
152 startifdown)
153 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
154 if [ $n == 0 ]; then
155 start
156 else
157 echo "$n instance of onos running"
158 fi
159 ;;
160 stop)
161 stop
162 ;;
163 deldb)
164 deldb
165 ;;
166 status)
167 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
168 echo "$n instance of onos running"
169 ;;
170 *)
Yuta HIGUCHI645a6682014-01-02 11:10:12 -0800171 echo "Usage: $0 {start|stop|status|startifdown}"
Pankaj Berde1b399bb2013-06-12 11:04:11 -0700172 exit 1
173esac