blob: d4ea834c4e5ef681e02bd580e0fdd70c494c08fc [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
admin6bdc9992013-02-06 11:06:02 -080027#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000028#<appender-ref ref="STDOUT" />
29
30function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000031 logfile=$1
32 nr_max=${2:-10}
33 if [ -f $logfile ]; then
34 for i in `seq $(expr $nr_max - 1) -1 1`; do
35 if [ -f ${logfile}.${i} ]; then
36 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
37 fi
38 done
39 mv $logfile $logfile.1
40 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000041}
42
43function start {
44 if [ ! -d ${LOGDIR} ]; then
45 mkdir -p ${LOGDIR}
46 fi
47 # Backup log files
48 for log in ${LOGS}; do
49 echo "rotate log: $log"
50 if [ -f ${log} ]; then
51 lotate ${log}
52 fi
53 done
54
Jonathan Hart0ae27772013-03-19 13:03:52 -070055# Create a logback file if required
56 cat <<EOF_LOGBACK >${FL_LOGBACK}
57<configuration scan="true" debug="true">
58<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
59<encoder>
60<pattern>%level [%logger:%thread] %msg%n</pattern>
61</encoder>
62</appender>
63
64<appender name="FILE" class="ch.qos.logback.core.FileAppender">
65<file>${FL_LOG}</file>
66<encoder>
67<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
68</encoder>
69</appender>
70
71<logger name="org" level="WARN"/>
72<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
73<logger name="net.floodlightcontroller.logging" level="WARN"/>
74
75<root level="DEBUG">
76<appender-ref ref="FILE" />
77</root>
78</configuration>
79EOF_LOGBACK
80
Ubuntu08edc7a2013-01-30 17:59:19 +000081 # Run floodlight
82 echo "Starting ONOS controller ..."
83 echo
Jonathan Harte4997b92013-03-22 09:57:41 -070084 #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 -070085 #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 -070086
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -070087 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 &
88
89 echo "Waiting for ONOS to start..."
90 COUNT=0
91 ESTATE=0
92 while [ "$COUNT" != "10" ]; do
93 COUNT=$((COUNT + 1))
94 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
95 if [ "$n" -ge "1" ]; then
96 exit 0
97 fi
98 sleep $COUNT
99 done
100 echo "Timed out"
101 exit 1
Jonathan Harte4997b92013-03-22 09:57:41 -0700102
Ubuntuaea2a682013-02-08 08:30:10 +0000103# 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 +0000104# 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 +0000105}
106
107function stop {
108 # Kill the existing processes
Pankaj Berde77b58512013-04-05 12:06:37 -0700109 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
Ubuntu08edc7a2013-01-30 17:59:19 +0000110 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
111 pids="$flpid $tdpid"
112 for p in ${pids}; do
113 if [ x$p != "x" ]; then
Pavlin Radoslavovb531d712013-03-29 15:13:43 -0700114 kill -KILL $p
Ubuntu08edc7a2013-01-30 17:59:19 +0000115 echo "Killed existing prosess (pid: $p)"
116 fi
117 done
118}
119
admin6bdc9992013-02-06 11:06:02 -0800120function deldb {
121 # Delete the berkeley db database
122 if [ -d "/tmp/cassandra.titan" ]; then
123 rm -rf /tmp/cassandra.titan
124 mkdir /tmp/cassandra.titan
125 fi
126}
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000127function check_db {
128 if [ -d "/tmp/cassandra.titan" ]; then
129 echo "Cassandra is running on local berkely db. Exitting"
130 exit
131 fi
132 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000133 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000134 echo "Cassandra is not running. Exitting"
135 exit
136 fi
137}
admin6bdc9992013-02-06 11:06:02 -0800138
Ubuntu08edc7a2013-01-30 17:59:19 +0000139case "$1" in
140 start)
141 stop
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000142 check_db
Ubuntu08edc7a2013-01-30 17:59:19 +0000143 start
144 ;;
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000145 startifdown)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700146 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000147 if [ $n == 0 ]; then
148 start
149 else
150 echo "$n instance of onos running"
151 fi
152 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000153 stop)
154 stop
155 ;;
admin6bdc9992013-02-06 11:06:02 -0800156 deldb)
157 deldb
158 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000159 status)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700160 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Ubuntu08edc7a2013-01-30 17:59:19 +0000161 echo "$n instance of onos running"
162 ;;
163 *)
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000164 echo "Usage: $0 {start|stop|restart|status|startifdown}"
Ubuntu08edc7a2013-01-30 17:59:19 +0000165 exit 1
166esac