blob: dac03316f9550588ff460abd119c23a9fae67aef [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
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -07007ONOS_LOGBACK="${ONOS_HOME}/logback.xml"
8LOGDIR=${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"
20JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
Pankaj Berdeff1fe032013-06-27 14:59:00 -070021 -XX:+UseThreadPriorities \
22 -XX:ThreadPriorityPolicy=42 \
23 -XX:+UseCompressedOops \
24 -Dcassandra.compaction.priority=1 \
Pankaj Berde1b399bb2013-06-12 11:04:11 -070025 -Dcom.sun.management.jmxremote.port=7199 \
26 -Dcom.sun.management.jmxremote.ssl=false \
27 -Dcom.sun.management.jmxremote.authenticate=false"
28
29#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
30
Pankaj Berdebbd38612013-06-22 05:59:12 -070031# Set Main class to start ONOS core
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070032MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
Pankaj Berde1b399bb2013-06-12 11:04:11 -070033
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070034if [ -z "${MVN}" ]; then
35 MVN="mvn"
36fi
Pankaj Berde1b399bb2013-06-12 11:04:11 -070037#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
38#<appender-ref ref="STDOUT" />
39
40function lotate {
41 logfile=$1
42 nr_max=${2:-10}
43 if [ -f $logfile ]; then
44 for i in `seq $(expr $nr_max - 1) -1 1`; do
45 if [ -f ${logfile}.${i} ]; then
46 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
47 fi
48 done
49 mv $logfile $logfile.1
50 fi
51}
52
53function start {
54 if [ ! -d ${LOGDIR} ]; then
55 mkdir -p ${LOGDIR}
56 fi
57 # Backup log files
58 for log in ${LOGS}; do
59 echo "rotate log: $log"
60 if [ -f ${log} ]; then
61 lotate ${log}
62 fi
63 done
64
65# Create a logback file if required
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070066 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Pankaj Berde1b399bb2013-06-12 11:04:11 -070067<configuration scan="true" debug="true">
68<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
69<encoder>
70<pattern>%level [%logger:%thread] %msg%n</pattern>
71</encoder>
72</appender>
73
74<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070075<file>${ONOS_LOG}</file>
Pankaj Berde1b399bb2013-06-12 11:04:11 -070076<encoder>
77<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
78</encoder>
79</appender>
80
81<logger name="org" level="WARN"/>
82<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
83<logger name="net.floodlightcontroller.logging" level="WARN"/>
84
85<root level="DEBUG">
86<appender-ref ref="FILE" />
87</root>
88</configuration>
89EOF_LOGBACK
90
91 # Run floodlight
92 echo "Starting ONOS controller ..."
93 echo
Pankaj Berde1b399bb2013-06-12 11:04:11 -070094
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -070095 # XXX MVN has to run at the project top dir..
96 cd ${ONOS_HOME}
Masayoshi Kobayashia8e38352013-06-20 16:52:40 -070097 ${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 -070098
99 echo "Waiting for ONOS to start..."
100 COUNT=0
101 ESTATE=0
102 while [ "$COUNT" != "10" ]; do
103 COUNT=$((COUNT + 1))
104 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
105 if [ "$n" -ge "1" ]; then
106 exit 0
107 fi
108 sleep $COUNT
109 done
110 echo "Timed out"
111 exit 1
112
Pankaj Berdebbd38612013-06-22 05:59:12 -0700113 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 -0700114}
115
116function stop {
117 # Kill the existing processes
118 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
119 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
120 pids="$flpid $tdpid"
121 for p in ${pids}; do
122 if [ x$p != "x" ]; then
123 kill -KILL $p
Pankaj Berdebbd38612013-06-22 05:59:12 -0700124 echo "Killed existing process (pid: $p)"
Pankaj Berde1b399bb2013-06-12 11:04:11 -0700125 fi
126 done
127}
128
129function deldb {
130 # Delete the cassandra data
131 if [ -d "/tmp/cassandra" ]; then
132 rm -rf /tmp/cassandra/*
133 fi
134}
135
136case "$1" in
137 start)
138 stop
139 start
140 ;;
141 startifdown)
142 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
143 if [ $n == 0 ]; then
144 start
145 else
146 echo "$n instance of onos running"
147 fi
148 ;;
149 stop)
150 stop
151 ;;
152 deldb)
153 deldb
154 ;;
155 status)
156 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
157 echo "$n instance of onos running"
158 ;;
159 *)
160 echo "Usage: $0 {start|stop|restart|status|startifdown}"
161 exit 1
162esac