blob: f2da4e0830e82071d0f4041b9a882a33c1313194 [file] [log] [blame]
mininet4a828f22013-12-10 14:22:39 -08001#!/bin/bash
2
3# Set paths
4if [ -z "${ONOS_HOME}" ]; then
5 ONOS_HOME=`dirname $0`
6fi
7
8## Because the script change dir to $ONOS_HOME, we can set ONOS_LOGBACK and LOGDIR relative to $ONOS_HOME
9#ONOS_LOGBACK="${ONOS_HOME}/logback.`hostname`.xml"
10#LOGDIR=${ONOS_HOME}/onos-logs
11ONOS_LOGBACK="./logback.`hostname`.xml"
12LOGDIR=./onos-logs
13ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
14PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap"
15LOGS="$ONOS_LOG $PCAP_LOG"
16
17# Set JVM options
18JVM_OPTS=""
19## If you want JaCoCo Code Coverage reports... uncomment line below
20JVM_OPTS="$JVM_OPTS -javaagent:${ONOS_HOME}/lib/jacocoagent.jar=dumponexit=true,output=file,destfile=${LOGDIR}/jacoco.exec"
21JVM_OPTS="$JVM_OPTS -server -d64"
22#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
23JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
24#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
25JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
26JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
27JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
28JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
29#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
30JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
31 -XX:+UseThreadPriorities \
32 -XX:ThreadPriorityPolicy=42 \
33 -XX:+UseCompressedOops \
34 -Dcom.sun.management.jmxremote.port=7189 \
35 -Dcom.sun.management.jmxremote.ssl=false \
36 -Dcom.sun.management.jmxremote.authenticate=false"
37JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j"
38
39# Set ONOS core main class
40MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
41
42if [ -z "${MVN}" ]; then
43 MVN="mvn -o"
44fi
45
Yuta HIGUCHIfbd9a7e2014-03-23 00:18:50 -070046CPFILE=${ONOS_HOME}/.javacp.`hostname`
47if [ ! -f ${CPFILE} ]; then
Yuta HIGUCHI8d9723d2013-12-21 00:10:07 -080048 ${MVN} -f ${ONOS_HOME}/pom.xml compile
49fi
Yuta HIGUCHIfbd9a7e2014-03-23 00:18:50 -070050JAVA_CP=`cat ${CPFILE}`
Yuta HIGUCHI8d9723d2013-12-21 00:10:07 -080051JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes"
52
mininet4a828f22013-12-10 14:22:39 -080053#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
54#<appender-ref ref="STDOUT" />
55
56function lotate {
57 logfile=$1
58 nr_max=${2:-10}
59 if [ -f $logfile ]; then
60 for i in `seq $(expr $nr_max - 1) -1 1`; do
61 if [ -f ${logfile}.${i} ]; then
62 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
63 fi
64 done
65 mv $logfile $logfile.1
66 fi
67}
68
69function start {
70 if [ ! -d ${LOGDIR} ]; then
71 mkdir -p ${LOGDIR}
72 fi
73 # Backup log files
74 for log in ${LOGS}; do
75 echo "rotate log: $log"
76 if [ -f ${log} ]; then
77 lotate ${log}
78 fi
79 done
80
81# Create a logback file if required
82 if [ ! -f ${ONOS_LOGBACK} ]; then
83 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
84<configuration scan="true" debug="true">
85<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
86<encoder>
87<pattern>%level [%logger:%thread] %msg%n</pattern>
88</encoder>
89</appender>
90
91<appender name="FILE" class="ch.qos.logback.core.FileAppender">
92<file>${ONOS_LOG}</file>
93<encoder>
94<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
95</encoder>
96</appender>
97
98<logger name="org" level="WARN"/>
99<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
100<logger name="net.floodlightcontroller.logging" level="WARN"/>
Jonathan Hart64a036d2014-01-15 10:58:01 -0800101<logger name="com.thinkaurelius.titan" level="INFO"/>
mininet4a828f22013-12-10 14:22:39 -0800102
103<root level="DEBUG">
104<appender-ref ref="FILE" />
105</root>
106</configuration>
107EOF_LOGBACK
108 fi
109
Yuta HIGUCHI4fb214c2013-12-10 14:56:52 -0800110 # Run ONOS
mininet4a828f22013-12-10 14:22:39 -0800111 echo "Starting ONOS controller ..."
112 echo
113
114 # XXX : MVN has to run at the project top dir
115 echo $ONOS_HOME
116 cd ${ONOS_HOME}
Yuta HIGUCHI8d9723d2013-12-21 00:10:07 -0800117 java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ./conf/onos.properties > ${LOGDIR}/onos.`hostname`.stdout 2>${LOGDIR}/onos.`hostname`.stderr &
mininet4a828f22013-12-10 14:22:39 -0800118
119 echo "Waiting for ONOS to start..."
120 COUNT=0
121 ESTATE=0
122 while [ "$COUNT" != "10" ]; do
123 echo -n "."
124 sleep 1
125# COUNT=$((COUNT + 1))
126# sleep $COUNT
127 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
128 if [ "$n" -ge "1" ]; then
129 echo ""
130 exit 0
131 fi
132 done
133 echo "Timed out"
134 exit 1
135
136# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
137# sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1
138}
139
140function stop {
141 # Kill the existing processes
142 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
143 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
144 pids="$flpid $tdpid"
145 for p in ${pids}; do
146 if [ x$p != "x" ]; then
147 kill -TERM $p
148 echo "Killed existing process (pid: $p)"
149 fi
150 done
151}
152
153function check_db {
154 if [ -d "/tmp/cassandra.titan" ]; then
155 echo "Cassandra is running on local berkely db. Exitting"
156 exit
157 fi
158 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
159 if [ x$n == "x0" ]; then
160 echo "Cassandra is not running. Exitting"
161 exit
162 fi
163}
164
165case "$1" in
166 start)
167 stop
168 check_db
169 start
170 ;;
171 startifdown)
172 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
173 if [ $n == 0 ]; then
174 start
175 else
176 echo "$n instance of onos running"
177 fi
178 ;;
179 stop)
180 stop
181 ;;
182 status)
183 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
184 echo "$n instance of onos running"
185 ;;
186 *)
Yuta HIGUCHI645a6682014-01-02 11:10:12 -0800187 echo "Usage: $0 {start|stop|status|startifdown}"
mininet4a828f22013-12-10 14:22:39 -0800188 exit 1
189esac