blob: 13ea0ac0ebbdb8fdcfd9bbc8719f8138fd55af22 [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=""
Jonathan Hartf7562782013-04-03 19:50:36 -070019JVM_OPTS="$JVM_OPTS -server -d64"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070020#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
21JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
22#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070023JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Jonathan Hartf7562782013-04-03 19:50:36 -070024JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
25JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070026JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
Ubuntu08edc7a2013-01-30 17:59:19 +000027#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070028JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
29 -XX:+UseThreadPriorities \
30 -XX:ThreadPriorityPolicy=42 \
31 -XX:+UseCompressedOops \
32 -Dcom.sun.management.jmxremote.port=7189 \
33 -Dcom.sun.management.jmxremote.ssl=false \
34 -Dcom.sun.management.jmxremote.authenticate=false"
Ubuntu08edc7a2013-01-30 17:59:19 +000035
Pankaj Berdebbd38612013-06-22 05:59:12 -070036# Set ONOS core main class
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070037MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
Ubuntu08edc7a2013-01-30 17:59:19 +000038
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070039if [ -z "${MVN}" ]; then
Masayoshi Kobayashi99730902013-06-27 23:23:20 -070040 MVN="mvn -o"
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070041fi
42
admin6bdc9992013-02-06 11:06:02 -080043#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000044#<appender-ref ref="STDOUT" />
45
46function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000047 logfile=$1
48 nr_max=${2:-10}
49 if [ -f $logfile ]; then
50 for i in `seq $(expr $nr_max - 1) -1 1`; do
51 if [ -f ${logfile}.${i} ]; then
52 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
53 fi
54 done
55 mv $logfile $logfile.1
56 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000057}
58
59function start {
60 if [ ! -d ${LOGDIR} ]; then
61 mkdir -p ${LOGDIR}
62 fi
63 # Backup log files
64 for log in ${LOGS}; do
65 echo "rotate log: $log"
66 if [ -f ${log} ]; then
67 lotate ${log}
68 fi
69 done
70
Jonathan Hart0ae27772013-03-19 13:03:52 -070071# Create a logback file if required
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070072 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Jonathan Hart0ae27772013-03-19 13:03:52 -070073<configuration scan="true" debug="true">
74<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
75<encoder>
76<pattern>%level [%logger:%thread] %msg%n</pattern>
77</encoder>
78</appender>
79
80<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070081<file>${ONOS_LOG}</file>
Jonathan Hart0ae27772013-03-19 13:03:52 -070082<encoder>
83<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
84</encoder>
85</appender>
86
87<logger name="org" level="WARN"/>
88<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
89<logger name="net.floodlightcontroller.logging" level="WARN"/>
90
91<root level="DEBUG">
92<appender-ref ref="FILE" />
93</root>
94</configuration>
95EOF_LOGBACK
96
Ubuntu08edc7a2013-01-30 17:59:19 +000097 # Run floodlight
98 echo "Starting ONOS controller ..."
99 echo
Jonathan Harte4997b92013-03-22 09:57:41 -0700100
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -0700101 # XXX : MVN has to run at the project top dir
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700102 echo $ONOS_HOME
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -0700103 cd ${ONOS_HOME}
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700104 pwd
105 echo "${MVN} exec:exec -Dexec.executable=\"java\" -Dexec.args=\"${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ./conf/onos.properties\""
106
107 ${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 -0700108
109 echo "Waiting for ONOS to start..."
110 COUNT=0
111 ESTATE=0
112 while [ "$COUNT" != "10" ]; do
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700113 echo -n "."
114 sleep 1
115# COUNT=$((COUNT + 1))
116# sleep $COUNT
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700117 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
118 if [ "$n" -ge "1" ]; then
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700119 echo ""
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700120 exit 0
121 fi
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700122 done
123 echo "Timed out"
124 exit 1
Jonathan Harte4997b92013-03-22 09:57:41 -0700125
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -0700126# 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 +0000127# 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 +0000128}
129
130function stop {
131 # Kill the existing processes
Pankaj Berde77b58512013-04-05 12:06:37 -0700132 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
Ubuntu08edc7a2013-01-30 17:59:19 +0000133 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
134 pids="$flpid $tdpid"
135 for p in ${pids}; do
136 if [ x$p != "x" ]; then
Pavlin Radoslavovb531d712013-03-29 15:13:43 -0700137 kill -KILL $p
Pankaj Berdef71f6cb2013-06-27 18:30:53 -0700138 echo "Killed existing process (pid: $p)"
Ubuntu08edc7a2013-01-30 17:59:19 +0000139 fi
140 done
141}
142
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000143function check_db {
144 if [ -d "/tmp/cassandra.titan" ]; then
145 echo "Cassandra is running on local berkely db. Exitting"
146 exit
147 fi
148 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000149 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000150 echo "Cassandra is not running. Exitting"
151 exit
152 fi
153}
admin6bdc9992013-02-06 11:06:02 -0800154
Ubuntu08edc7a2013-01-30 17:59:19 +0000155case "$1" in
156 start)
157 stop
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000158 check_db
Ubuntu08edc7a2013-01-30 17:59:19 +0000159 start
160 ;;
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000161 startifdown)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700162 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000163 if [ $n == 0 ]; then
164 start
165 else
166 echo "$n instance of onos running"
167 fi
168 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000169 stop)
170 stop
171 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000172 status)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700173 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Ubuntu08edc7a2013-01-30 17:59:19 +0000174 echo "$n instance of onos running"
175 ;;
176 *)
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000177 echo "Usage: $0 {start|stop|restart|status|startifdown}"
Ubuntu08edc7a2013-01-30 17:59:19 +0000178 exit 1
179esac