blob: 8688f691c77654c11d7ee35194ee2a79b987d355 [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"
Pankaj Berde80589902013-08-13 14:00:36 -070020JVM_OPTS="$JVM_OPTS -javaagent: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
Pankaj Berde1b399bb2013-06-12 11:04:11 -070039#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
40#<appender-ref ref="STDOUT" />
41
42function lotate {
43 logfile=$1
44 nr_max=${2:-10}
45 if [ -f $logfile ]; then
46 for i in `seq $(expr $nr_max - 1) -1 1`; do
47 if [ -f ${logfile}.${i} ]; then
48 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
49 fi
50 done
51 mv $logfile $logfile.1
52 fi
53}
54
55function start {
56 if [ ! -d ${LOGDIR} ]; then
57 mkdir -p ${LOGDIR}
58 fi
59 # Backup log files
60 for log in ${LOGS}; do
61 echo "rotate log: $log"
62 if [ -f ${log} ]; then
63 lotate ${log}
64 fi
65 done
66
67# Create a logback file if required
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070068 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Pankaj Berde1b399bb2013-06-12 11:04:11 -070069<configuration scan="true" debug="true">
70<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
71<encoder>
72<pattern>%level [%logger:%thread] %msg%n</pattern>
73</encoder>
74</appender>
75
76<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070077<file>${ONOS_LOG}</file>
Pankaj Berde1b399bb2013-06-12 11:04:11 -070078<encoder>
79<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
80</encoder>
81</appender>
82
83<logger name="org" level="WARN"/>
84<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
85<logger name="net.floodlightcontroller.logging" level="WARN"/>
86
87<root level="DEBUG">
88<appender-ref ref="FILE" />
89</root>
90</configuration>
91EOF_LOGBACK
92
93 # Run floodlight
94 echo "Starting ONOS controller ..."
95 echo
Pankaj Berde1b399bb2013-06-12 11:04:11 -070096
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -070097 # XXX MVN has to run at the project top dir..
98 cd ${ONOS_HOME}
Naoki Shiota6e44b372013-10-14 14:33:58 -070099 echo "${MVN} exec:exec -Dexec.executable=\"java\" -Dexec.args=\"${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos-embedded.properties\""
Masayoshi Kobayashia8e38352013-06-20 16:52:40 -0700100 ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos-embedded.properties" > ${LOGDIR}/onos.stdout 2>${LOGDIR}/onos.stderr &
Pankaj Berde1b399bb2013-06-12 11:04:11 -0700101
102 echo "Waiting for ONOS to start..."
103 COUNT=0
104 ESTATE=0
105 while [ "$COUNT" != "10" ]; do
106 COUNT=$((COUNT + 1))
107 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
108 if [ "$n" -ge "1" ]; then
109 exit 0
110 fi
111 sleep $COUNT
112 done
113 echo "Timed out"
114 exit 1
115
Pankaj Berdebbd38612013-06-22 05:59:12 -0700116 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 -0700117}
118
119function stop {
120 # Kill the existing processes
121 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
122 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
123 pids="$flpid $tdpid"
124 for p in ${pids}; do
125 if [ x$p != "x" ]; then
126 kill -KILL $p
Pankaj Berdebbd38612013-06-22 05:59:12 -0700127 echo "Killed existing process (pid: $p)"
Pankaj Berde1b399bb2013-06-12 11:04:11 -0700128 fi
129 done
130}
131
132function deldb {
133 # Delete the cassandra data
134 if [ -d "/tmp/cassandra" ]; then
135 rm -rf /tmp/cassandra/*
136 fi
137}
138
139case "$1" in
140 start)
141 stop
142 start
143 ;;
144 startifdown)
145 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
146 if [ $n == 0 ]; then
147 start
148 else
149 echo "$n instance of onos running"
150 fi
151 ;;
152 stop)
153 stop
154 ;;
155 deldb)
156 deldb
157 ;;
158 status)
159 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
160 echo "$n instance of onos running"
161 ;;
162 *)
163 echo "Usage: $0 {start|stop|restart|status|startifdown}"
164 exit 1
165esac