blob: 14adfb022af50f4b231dafe0286de18c235618e2 [file] [log] [blame]
Ubuntu08edc7a2013-01-30 17:59:19 +00001#!/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 Kobayashi99730902013-06-27 23:23:20 -07007
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -07008## 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
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070013ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
Ubuntu08edc7a2013-01-30 17:59:19 +000014PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070015LOGS="$ONOS_LOG $PCAP_LOG"
Ubuntu08edc7a2013-01-30 17:59:19 +000016
17# Set JVM options
18JVM_OPTS=""
timlindberg8b13e702013-07-17 14:45:50 -070019## 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"
Jonathan Hartf7562782013-04-03 19:50:36 -070021JVM_OPTS="$JVM_OPTS -server -d64"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070022#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"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070025JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Jonathan Hartf7562782013-04-03 19:50:36 -070026JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
27JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070028JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
Ubuntu08edc7a2013-01-30 17:59:19 +000029#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070030JVM_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"
Ubuntu08edc7a2013-01-30 17:59:19 +000037
Pankaj Berdebbd38612013-06-22 05:59:12 -070038# Set ONOS core main class
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070039MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
Ubuntu08edc7a2013-01-30 17:59:19 +000040
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070041if [ -z "${MVN}" ]; then
Masayoshi Kobayashi99730902013-06-27 23:23:20 -070042 MVN="mvn -o"
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070043fi
44
admin6bdc9992013-02-06 11:06:02 -080045#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000046#<appender-ref ref="STDOUT" />
47
48function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000049 logfile=$1
50 nr_max=${2:-10}
51 if [ -f $logfile ]; then
52 for i in `seq $(expr $nr_max - 1) -1 1`; do
53 if [ -f ${logfile}.${i} ]; then
54 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
55 fi
56 done
57 mv $logfile $logfile.1
58 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000059}
60
61function start {
62 if [ ! -d ${LOGDIR} ]; then
63 mkdir -p ${LOGDIR}
64 fi
65 # Backup log files
66 for log in ${LOGS}; do
67 echo "rotate log: $log"
68 if [ -f ${log} ]; then
69 lotate ${log}
70 fi
71 done
72
Jonathan Hart0ae27772013-03-19 13:03:52 -070073# Create a logback file if required
Jonathan Hartb5ad4612013-09-27 14:47:25 +120074 if [ ! -f ${ONOS_LOGBACK} ]; then
75 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Jonathan Hart0ae27772013-03-19 13:03:52 -070076<configuration scan="true" debug="true">
77<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
78<encoder>
79<pattern>%level [%logger:%thread] %msg%n</pattern>
80</encoder>
81</appender>
82
83<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070084<file>${ONOS_LOG}</file>
Jonathan Hart0ae27772013-03-19 13:03:52 -070085<encoder>
86<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
87</encoder>
88</appender>
89
90<logger name="org" level="WARN"/>
91<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
92<logger name="net.floodlightcontroller.logging" level="WARN"/>
93
94<root level="DEBUG">
95<appender-ref ref="FILE" />
96</root>
97</configuration>
98EOF_LOGBACK
Jonathan Hartb5ad4612013-09-27 14:47:25 +120099 fi
Jonathan Hart0ae27772013-03-19 13:03:52 -0700100
Ubuntu08edc7a2013-01-30 17:59:19 +0000101 # Run floodlight
102 echo "Starting ONOS controller ..."
103 echo
Jonathan Harte4997b92013-03-22 09:57:41 -0700104
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -0700105 # XXX : MVN has to run at the project top dir
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700106 echo $ONOS_HOME
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -0700107 cd ${ONOS_HOME}
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700108 pwd
109 echo "${MVN} exec:exec -Dexec.executable=\"java\" -Dexec.args=\"${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ./conf/onos.properties\""
110
111 ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ./conf/onos.properties" > ${LOGDIR}/onos.`hostname`.stdout 2>${LOGDIR}/onos.`hostname`.stderr &
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700112
113 echo "Waiting for ONOS to start..."
114 COUNT=0
115 ESTATE=0
116 while [ "$COUNT" != "10" ]; do
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700117 echo -n "."
118 sleep 1
119# COUNT=$((COUNT + 1))
120# sleep $COUNT
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700121 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
122 if [ "$n" -ge "1" ]; then
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700123 echo ""
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700124 exit 0
125 fi
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700126 done
127 echo "Timed out"
128 exit 1
Jonathan Harte4997b92013-03-22 09:57:41 -0700129
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -0700130# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
Masayoshi Kobayashi8849a662013-03-14 22:18:51 +0000131# sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1
Ubuntu08edc7a2013-01-30 17:59:19 +0000132}
133
134function stop {
135 # Kill the existing processes
Pankaj Berde77b58512013-04-05 12:06:37 -0700136 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
Ubuntu08edc7a2013-01-30 17:59:19 +0000137 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
138 pids="$flpid $tdpid"
139 for p in ${pids}; do
140 if [ x$p != "x" ]; then
timlindberg8b13e702013-07-17 14:45:50 -0700141 kill -TERM $p
Pankaj Berdef71f6cb2013-06-27 18:30:53 -0700142 echo "Killed existing process (pid: $p)"
Ubuntu08edc7a2013-01-30 17:59:19 +0000143 fi
144 done
145}
146
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000147function check_db {
148 if [ -d "/tmp/cassandra.titan" ]; then
149 echo "Cassandra is running on local berkely db. Exitting"
150 exit
151 fi
152 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000153 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000154 echo "Cassandra is not running. Exitting"
155 exit
156 fi
157}
admin6bdc9992013-02-06 11:06:02 -0800158
Ubuntu08edc7a2013-01-30 17:59:19 +0000159case "$1" in
160 start)
161 stop
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000162 check_db
Ubuntu08edc7a2013-01-30 17:59:19 +0000163 start
164 ;;
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000165 startifdown)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700166 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000167 if [ $n == 0 ]; then
168 start
169 else
170 echo "$n instance of onos running"
171 fi
172 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000173 stop)
174 stop
175 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000176 status)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700177 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Ubuntu08edc7a2013-01-30 17:59:19 +0000178 echo "$n instance of onos running"
179 ;;
180 *)
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000181 echo "Usage: $0 {start|stop|restart|status|startifdown}"
Ubuntu08edc7a2013-01-30 17:59:19 +0000182 exit 1
183esac