blob: ca21907fa4edcb0c75609a6b7d4cdd364fa5c959 [file] [log] [blame]
Ubuntu08edc7a2013-01-30 17:59:19 +00001#!/bin/bash
2
3# Set paths
4FL_HOME=`dirname $0`
5FL_JAR="${FL_HOME}/target/floodlight.jar"
Jonathan Harte4997b92013-03-22 09:57:41 -07006FL_ONLY_JAR="${FL_HOME}/target/floodlight-only.jar"
Ubuntu08edc7a2013-01-30 17:59:19 +00007FL_LOGBACK="${FL_HOME}/logback.xml"
8LOGDIR=${FL_HOME}/onos-logs
9FL_LOG="${LOGDIR}/onos.`hostname`.log"
10PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap"
11LOGS="$FL_LOG $PCAP_LOG"
12
13# Set JVM options
14JVM_OPTS=""
Jonathan Hartf7562782013-04-03 19:50:36 -070015JVM_OPTS="$JVM_OPTS -server -d64"
16JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
17JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
18JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
19JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
Ubuntu08edc7a2013-01-30 17:59:19 +000020#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
21
22# Set classpath to include titan libs
Jonathan Harte4997b92013-03-22 09:57:41 -070023#CLASSPATH=`echo ${FL_HOME}/lib/*.jar ${FL_HOME}/lib/titan/*.jar | sed 's/ /:/g'`
24CLASSPATH="${FL_ONLY_JAR}:${FL_HOME}/lib/*:${FL_HOME}/lib/titan/*"
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070025MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
Ubuntu08edc7a2013-01-30 17:59:19 +000026
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070027if [ -z "${MVN}" ]; then
28 MVN="mvn"
29fi
30
admin6bdc9992013-02-06 11:06:02 -080031#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000032#<appender-ref ref="STDOUT" />
33
34function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000035 logfile=$1
36 nr_max=${2:-10}
37 if [ -f $logfile ]; then
38 for i in `seq $(expr $nr_max - 1) -1 1`; do
39 if [ -f ${logfile}.${i} ]; then
40 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
41 fi
42 done
43 mv $logfile $logfile.1
44 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000045}
46
47function start {
48 if [ ! -d ${LOGDIR} ]; then
49 mkdir -p ${LOGDIR}
50 fi
51 # Backup log files
52 for log in ${LOGS}; do
53 echo "rotate log: $log"
54 if [ -f ${log} ]; then
55 lotate ${log}
56 fi
57 done
58
Jonathan Hart0ae27772013-03-19 13:03:52 -070059# Create a logback file if required
60 cat <<EOF_LOGBACK >${FL_LOGBACK}
61<configuration scan="true" debug="true">
62<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
63<encoder>
64<pattern>%level [%logger:%thread] %msg%n</pattern>
65</encoder>
66</appender>
67
68<appender name="FILE" class="ch.qos.logback.core.FileAppender">
69<file>${FL_LOG}</file>
70<encoder>
71<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
72</encoder>
73</appender>
74
75<logger name="org" level="WARN"/>
76<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
77<logger name="net.floodlightcontroller.logging" level="WARN"/>
78
79<root level="DEBUG">
80<appender-ref ref="FILE" />
81</root>
82</configuration>
83EOF_LOGBACK
84
Ubuntu08edc7a2013-01-30 17:59:19 +000085 # Run floodlight
86 echo "Starting ONOS controller ..."
87 echo
Jonathan Harte4997b92013-03-22 09:57:41 -070088 #java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ${FL_HOME}/onos.properties > /dev/null 2>&1 &
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -070089 #java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -cp ${CLASSPATH} ${MAIN_CLASS} -cf ${FL_HOME}/onos.properties > /dev/n
Jonathan Harte4997b92013-03-22 09:57:41 -070090
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070091 ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${FL_HOME}/onos.properties" > ${LOGDIR}/onos.stdout 2>${LOGDIR}/onos.stderr &
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -070092
93 echo "Waiting for ONOS to start..."
94 COUNT=0
95 ESTATE=0
96 while [ "$COUNT" != "10" ]; do
97 COUNT=$((COUNT + 1))
98 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
99 if [ "$n" -ge "1" ]; then
100 exit 0
101 fi
102 sleep $COUNT
103 done
104 echo "Timed out"
105 exit 1
Jonathan Harte4997b92013-03-22 09:57:41 -0700106
Ubuntuaea2a682013-02-08 08:30:10 +0000107# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
Masayoshi Kobayashi8849a662013-03-14 22:18:51 +0000108# 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 +0000109}
110
111function stop {
112 # Kill the existing processes
Pankaj Berde77b58512013-04-05 12:06:37 -0700113 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
Ubuntu08edc7a2013-01-30 17:59:19 +0000114 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
115 pids="$flpid $tdpid"
116 for p in ${pids}; do
117 if [ x$p != "x" ]; then
Pavlin Radoslavovb531d712013-03-29 15:13:43 -0700118 kill -KILL $p
Ubuntu08edc7a2013-01-30 17:59:19 +0000119 echo "Killed existing prosess (pid: $p)"
120 fi
121 done
122}
123
admin6bdc9992013-02-06 11:06:02 -0800124function deldb {
125 # Delete the berkeley db database
126 if [ -d "/tmp/cassandra.titan" ]; then
127 rm -rf /tmp/cassandra.titan
128 mkdir /tmp/cassandra.titan
129 fi
130}
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000131function check_db {
132 if [ -d "/tmp/cassandra.titan" ]; then
133 echo "Cassandra is running on local berkely db. Exitting"
134 exit
135 fi
136 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000137 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000138 echo "Cassandra is not running. Exitting"
139 exit
140 fi
141}
admin6bdc9992013-02-06 11:06:02 -0800142
Ubuntu08edc7a2013-01-30 17:59:19 +0000143case "$1" in
144 start)
145 stop
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000146 check_db
Ubuntu08edc7a2013-01-30 17:59:19 +0000147 start
148 ;;
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000149 startifdown)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700150 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000151 if [ $n == 0 ]; then
152 start
153 else
154 echo "$n instance of onos running"
155 fi
156 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000157 stop)
158 stop
159 ;;
admin6bdc9992013-02-06 11:06:02 -0800160 deldb)
161 deldb
162 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000163 status)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700164 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Ubuntu08edc7a2013-01-30 17:59:19 +0000165 echo "$n instance of onos running"
166 ;;
167 *)
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000168 echo "Usage: $0 {start|stop|restart|status|startifdown}"
Ubuntu08edc7a2013-01-30 17:59:19 +0000169 exit 1
170esac