blob: 06e25135c4f6d818938179ed4f587e84319edc31 [file] [log] [blame]
Pankaj Berde1b399bb2013-06-12 11:04:11 -07001#!/bin/bash
2
3# Set paths
4FL_HOME=`dirname $0`
5FL_JAR="${FL_HOME}/target/floodlight.jar"
6FL_ONLY_JAR="${FL_HOME}/target/floodlight-only.jar"
7FL_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=""
15JVM_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 \
20 -Dcom.sun.management.jmxremote.port=7199 \
21 -Dcom.sun.management.jmxremote.ssl=false \
22 -Dcom.sun.management.jmxremote.authenticate=false"
23
24#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
25
26# Set classpath to include titan libs
27#CLASSPATH=`echo ${FL_HOME}/lib/*.jar ${FL_HOME}/lib/titan/*.jar | sed 's/ /:/g'`
28CLASSPATH="${FL_ONLY_JAR}:${FL_HOME}/lib/*:${FL_HOME}/lib/titan/*"
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070029MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
Pankaj Berde1b399bb2013-06-12 11:04:11 -070030
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070031if [ -z "${MVN}" ]; then
32 MVN="mvn"
33fi
Pankaj Berde1b399bb2013-06-12 11:04:11 -070034#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
35#<appender-ref ref="STDOUT" />
36
37function lotate {
38 logfile=$1
39 nr_max=${2:-10}
40 if [ -f $logfile ]; then
41 for i in `seq $(expr $nr_max - 1) -1 1`; do
42 if [ -f ${logfile}.${i} ]; then
43 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
44 fi
45 done
46 mv $logfile $logfile.1
47 fi
48}
49
50function start {
51 if [ ! -d ${LOGDIR} ]; then
52 mkdir -p ${LOGDIR}
53 fi
54 # Backup log files
55 for log in ${LOGS}; do
56 echo "rotate log: $log"
57 if [ -f ${log} ]; then
58 lotate ${log}
59 fi
60 done
61
62# Create a logback file if required
63 cat <<EOF_LOGBACK >${FL_LOGBACK}
64<configuration scan="true" debug="true">
65<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
66<encoder>
67<pattern>%level [%logger:%thread] %msg%n</pattern>
68</encoder>
69</appender>
70
71<appender name="FILE" class="ch.qos.logback.core.FileAppender">
72<file>${FL_LOG}</file>
73<encoder>
74<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
75</encoder>
76</appender>
77
78<logger name="org" level="WARN"/>
79<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
80<logger name="net.floodlightcontroller.logging" level="WARN"/>
81
82<root level="DEBUG">
83<appender-ref ref="FILE" />
84</root>
85</configuration>
86EOF_LOGBACK
87
88 # Run floodlight
89 echo "Starting ONOS controller ..."
90 echo
91 #java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ${FL_HOME}/onos.properties > /dev/null 2>&1 &
92 #java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -cp ${CLASSPATH} ${MAIN_CLASS} -cf ${FL_HOME}/onos.properties > /dev/n
93
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070094 ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${FL_HOME}/conf/onos-embedded.properties" > ${LOGDIR}/onos.stdout 2>${LOGDIR}/onos.stderr &
Pankaj Berde1b399bb2013-06-12 11:04:11 -070095
96 echo "Waiting for ONOS to start..."
97 COUNT=0
98 ESTATE=0
99 while [ "$COUNT" != "10" ]; do
100 COUNT=$((COUNT + 1))
101 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
102 if [ "$n" -ge "1" ]; then
103 exit 0
104 fi
105 sleep $COUNT
106 done
107 echo "Timed out"
108 exit 1
109
110# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
111# sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1
112}
113
114function stop {
115 # Kill the existing processes
116 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
117 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
118 pids="$flpid $tdpid"
119 for p in ${pids}; do
120 if [ x$p != "x" ]; then
121 kill -KILL $p
122 echo "Killed existing prosess (pid: $p)"
123 fi
124 done
125}
126
127function deldb {
128 # Delete the cassandra data
129 if [ -d "/tmp/cassandra" ]; then
130 rm -rf /tmp/cassandra/*
131 fi
132}
133
134case "$1" in
135 start)
136 stop
137 start
138 ;;
139 startifdown)
140 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
141 if [ $n == 0 ]; then
142 start
143 else
144 echo "$n instance of onos running"
145 fi
146 ;;
147 stop)
148 stop
149 ;;
150 deldb)
151 deldb
152 ;;
153 status)
154 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
155 echo "$n instance of onos running"
156 ;;
157 *)
158 echo "Usage: $0 {start|stop|restart|status|startifdown}"
159 exit 1
160esac