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