blob: 23c4bfabd90130f72a79e4d5078a4eb273c8b9ed [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 HIGUCHI8d9723d2013-12-21 00:10:07 -080046if [ ! -f ${ONOS_HOME}/.javacp ]; then
47 ${MVN} -f ${ONOS_HOME}/pom.xml compile
48fi
49JAVA_CP=`cat ${ONOS_HOME}/.javacp`
50JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes"
51
mininet4a828f22013-12-10 14:22:39 -080052#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
53#<appender-ref ref="STDOUT" />
54
55function lotate {
56 logfile=$1
57 nr_max=${2:-10}
58 if [ -f $logfile ]; then
59 for i in `seq $(expr $nr_max - 1) -1 1`; do
60 if [ -f ${logfile}.${i} ]; then
61 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
62 fi
63 done
64 mv $logfile $logfile.1
65 fi
66}
67
68function start {
69 if [ ! -d ${LOGDIR} ]; then
70 mkdir -p ${LOGDIR}
71 fi
72 # Backup log files
73 for log in ${LOGS}; do
74 echo "rotate log: $log"
75 if [ -f ${log} ]; then
76 lotate ${log}
77 fi
78 done
79
80# Create a logback file if required
81 if [ ! -f ${ONOS_LOGBACK} ]; then
82 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
83<configuration scan="true" debug="true">
84<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
85<encoder>
86<pattern>%level [%logger:%thread] %msg%n</pattern>
87</encoder>
88</appender>
89
90<appender name="FILE" class="ch.qos.logback.core.FileAppender">
91<file>${ONOS_LOG}</file>
92<encoder>
93<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
94</encoder>
95</appender>
96
97<logger name="org" level="WARN"/>
98<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
99<logger name="net.floodlightcontroller.logging" level="WARN"/>
100
101<root level="DEBUG">
102<appender-ref ref="FILE" />
103</root>
104</configuration>
105EOF_LOGBACK
106 fi
107
Yuta HIGUCHI4fb214c2013-12-10 14:56:52 -0800108 # Run ONOS
mininet4a828f22013-12-10 14:22:39 -0800109 echo "Starting ONOS controller ..."
110 echo
111
112 # XXX : MVN has to run at the project top dir
113 echo $ONOS_HOME
114 cd ${ONOS_HOME}
Yuta HIGUCHI8d9723d2013-12-21 00:10:07 -0800115 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 -0800116
117 echo "Waiting for ONOS to start..."
118 COUNT=0
119 ESTATE=0
120 while [ "$COUNT" != "10" ]; do
121 echo -n "."
122 sleep 1
123# COUNT=$((COUNT + 1))
124# sleep $COUNT
125 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
126 if [ "$n" -ge "1" ]; then
127 echo ""
128 exit 0
129 fi
130 done
131 echo "Timed out"
132 exit 1
133
134# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
135# sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1
136}
137
138function stop {
139 # Kill the existing processes
140 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
141 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
142 pids="$flpid $tdpid"
143 for p in ${pids}; do
144 if [ x$p != "x" ]; then
145 kill -TERM $p
146 echo "Killed existing process (pid: $p)"
147 fi
148 done
149}
150
151function check_db {
152 if [ -d "/tmp/cassandra.titan" ]; then
153 echo "Cassandra is running on local berkely db. Exitting"
154 exit
155 fi
156 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
157 if [ x$n == "x0" ]; then
158 echo "Cassandra is not running. Exitting"
159 exit
160 fi
161}
162
163case "$1" in
164 start)
165 stop
166 check_db
167 start
168 ;;
169 startifdown)
170 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
171 if [ $n == 0 ]; then
172 start
173 else
174 echo "$n instance of onos running"
175 fi
176 ;;
177 stop)
178 stop
179 ;;
180 status)
181 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
182 echo "$n instance of onos running"
183 ;;
184 *)
185 echo "Usage: $0 {start|stop|restart|status|startifdown}"
186 exit 1
187esac