blob: f140c84dc56caa2112c75f8d904f8e3e8bbd7f75 [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 Kobayashi7ee83b32013-06-20 16:49:01 -07007ONOS_LOGBACK="${ONOS_HOME}/logback.xml"
8LOGDIR=${ONOS_HOME}/onos-logs
9ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
Ubuntu08edc7a2013-01-30 17:59:19 +000010PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070011LOGS="$ONOS_LOG $PCAP_LOG"
Ubuntu08edc7a2013-01-30 17:59:19 +000012
13# Set JVM options
14JVM_OPTS=""
Jonathan Hartf7562782013-04-03 19:50:36 -070015JVM_OPTS="$JVM_OPTS -server -d64"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070016#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
17JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
18#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070019JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Jonathan Hartf7562782013-04-03 19:50:36 -070020JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
21JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070022JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
Ubuntu08edc7a2013-01-30 17:59:19 +000023#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070024JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
25 -XX:+UseThreadPriorities \
26 -XX:ThreadPriorityPolicy=42 \
27 -XX:+UseCompressedOops \
28 -Dcom.sun.management.jmxremote.port=7189 \
29 -Dcom.sun.management.jmxremote.ssl=false \
30 -Dcom.sun.management.jmxremote.authenticate=false"
Ubuntu08edc7a2013-01-30 17:59:19 +000031
Pankaj Berdebbd38612013-06-22 05:59:12 -070032# Set ONOS core main class
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070033MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
Ubuntu08edc7a2013-01-30 17:59:19 +000034
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070035if [ -z "${MVN}" ]; then
36 MVN="mvn"
37fi
38
admin6bdc9992013-02-06 11:06:02 -080039#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000040#<appender-ref ref="STDOUT" />
41
42function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000043 logfile=$1
44 nr_max=${2:-10}
45 if [ -f $logfile ]; then
46 for i in `seq $(expr $nr_max - 1) -1 1`; do
47 if [ -f ${logfile}.${i} ]; then
48 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
49 fi
50 done
51 mv $logfile $logfile.1
52 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000053}
54
55function start {
56 if [ ! -d ${LOGDIR} ]; then
57 mkdir -p ${LOGDIR}
58 fi
59 # Backup log files
60 for log in ${LOGS}; do
61 echo "rotate log: $log"
62 if [ -f ${log} ]; then
63 lotate ${log}
64 fi
65 done
66
Jonathan Hart0ae27772013-03-19 13:03:52 -070067# Create a logback file if required
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070068 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Jonathan Hart0ae27772013-03-19 13:03:52 -070069<configuration scan="true" debug="true">
70<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
71<encoder>
72<pattern>%level [%logger:%thread] %msg%n</pattern>
73</encoder>
74</appender>
75
76<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070077<file>${ONOS_LOG}</file>
Jonathan Hart0ae27772013-03-19 13:03:52 -070078<encoder>
79<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
80</encoder>
81</appender>
82
83<logger name="org" level="WARN"/>
84<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
85<logger name="net.floodlightcontroller.logging" level="WARN"/>
86
87<root level="DEBUG">
88<appender-ref ref="FILE" />
89</root>
90</configuration>
91EOF_LOGBACK
92
Ubuntu08edc7a2013-01-30 17:59:19 +000093 # Run floodlight
94 echo "Starting ONOS controller ..."
95 echo
Jonathan Harte4997b92013-03-22 09:57:41 -070096
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -070097 # XXX : MVN has to run at the project top dir
98 cd ${ONOS_HOME}
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.properties" > ${LOGDIR}/onos.stdout 2>${LOGDIR}/onos.stderr &
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -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
Jonathan Harte4997b92013-03-22 09:57:41 -0700114
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -0700115# 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 +0000116# 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 +0000117}
118
119function stop {
120 # Kill the existing processes
Pankaj Berde77b58512013-04-05 12:06:37 -0700121 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
Ubuntu08edc7a2013-01-30 17:59:19 +0000122 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
123 pids="$flpid $tdpid"
124 for p in ${pids}; do
125 if [ x$p != "x" ]; then
Pavlin Radoslavovb531d712013-03-29 15:13:43 -0700126 kill -KILL $p
Ubuntu08edc7a2013-01-30 17:59:19 +0000127 echo "Killed existing prosess (pid: $p)"
128 fi
129 done
130}
131
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000132function check_db {
133 if [ -d "/tmp/cassandra.titan" ]; then
134 echo "Cassandra is running on local berkely db. Exitting"
135 exit
136 fi
137 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000138 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000139 echo "Cassandra is not running. Exitting"
140 exit
141 fi
142}
admin6bdc9992013-02-06 11:06:02 -0800143
Ubuntu08edc7a2013-01-30 17:59:19 +0000144case "$1" in
145 start)
146 stop
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000147 check_db
Ubuntu08edc7a2013-01-30 17:59:19 +0000148 start
149 ;;
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000150 startifdown)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700151 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000152 if [ $n == 0 ]; then
153 start
154 else
155 echo "$n instance of onos running"
156 fi
157 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000158 stop)
159 stop
160 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000161 status)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700162 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Ubuntu08edc7a2013-01-30 17:59:19 +0000163 echo "$n instance of onos running"
164 ;;
165 *)
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000166 echo "Usage: $0 {start|stop|restart|status|startifdown}"
Ubuntu08edc7a2013-01-30 17:59:19 +0000167 exit 1
168esac