blob: 25929c643fdaf6ec73923ad03ce4e77049161fc8 [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"
20JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
Pankaj Berdeff1fe032013-06-27 14:59:00 -070021 -XX:+UseThreadPriorities \
22 -XX:ThreadPriorityPolicy=42 \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070023 -XX:+UseCompressedOops \
Pankaj Berdeff1fe032013-06-27 14:59:00 -070024 -Dcassandra.compaction.priority=1 \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070025 -Dcom.sun.management.jmxremote.port=7199 \
26 -Dcom.sun.management.jmxremote.ssl=false \
27 -Dcom.sun.management.jmxremote.authenticate=false"
Pavlin Radoslavov579983b2013-10-15 08:58:24 -070028JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j"
Pankaj Berde1b399bb2013-06-12 11:04:11 -070029
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}
Naoki Shiota6e44b372013-10-14 14:33:58 -070098 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 -070099 ${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 -0700100
101 echo "Waiting for ONOS to start..."
102 COUNT=0
103 ESTATE=0
104 while [ "$COUNT" != "10" ]; do
105 COUNT=$((COUNT + 1))
106 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
107 if [ "$n" -ge "1" ]; then
108 exit 0
109 fi
110 sleep $COUNT
111 done
112 echo "Timed out"
113 exit 1
114
Pankaj Berdebbd38612013-06-22 05:59:12 -0700115 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 -0700116}
117
118function stop {
119 # Kill the existing processes
120 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
121 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
122 pids="$flpid $tdpid"
123 for p in ${pids}; do
124 if [ x$p != "x" ]; then
125 kill -KILL $p
Pankaj Berdebbd38612013-06-22 05:59:12 -0700126 echo "Killed existing process (pid: $p)"
Pankaj Berde1b399bb2013-06-12 11:04:11 -0700127 fi
128 done
129}
130
131function deldb {
132 # Delete the cassandra data
133 if [ -d "/tmp/cassandra" ]; then
134 rm -rf /tmp/cassandra/*
135 fi
136}
137
138case "$1" in
139 start)
140 stop
141 start
142 ;;
143 startifdown)
144 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
145 if [ $n == 0 ]; then
146 start
147 else
148 echo "$n instance of onos running"
149 fi
150 ;;
151 stop)
152 stop
153 ;;
154 deldb)
155 deldb
156 ;;
157 status)
158 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
159 echo "$n instance of onos running"
160 ;;
161 *)
162 echo "Usage: $0 {start|stop|restart|status|startifdown}"
163 exit 1
164esac