blob: 9c1cf77098c9ddf9822a67b1793f0a38a581450d [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"
6FL_LOGBACK="${FL_HOME}/logback.xml"
7LOGDIR=${FL_HOME}/onos-logs
8FL_LOG="${LOGDIR}/onos.`hostname`.log"
9PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap"
10LOGS="$FL_LOG $PCAP_LOG"
11
12# Set JVM options
13JVM_OPTS=""
14#JVM_OPTS="$JVM_OPTS -server -d64"
15#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
16#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
17#JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
18#JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
19#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
20
21# Set classpath to include titan libs
22CLASSPATH=`echo ${FL_HOME}/lib/*.jar ${FL_HOME}/lib/titan/*.jar | sed 's/ /:/g'`
23
24# Create a logback file if required
25cat <<EOF_LOGBACK >${FL_LOGBACK}
26<configuration scan="true" debug="true">
27<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
28<encoder>
29<pattern>%level [%logger:%thread] %msg%n</pattern>
30</encoder>
31</appender>
32
33<appender name="FILE" class="ch.qos.logback.core.FileAppender">
34<file>${FL_LOG}</file>
35<encoder>
36<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
37</encoder>
38</appender>
39
40<logger name="org" level="WARN"/>
41<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
42<logger name="net.floodlightcontroller.logging" level="WARN"/>
43<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
44
45<root level="DEBUG">
46<appender-ref ref="FILE" />
47</root>
48</configuration>
49EOF_LOGBACK
50
51#<appender-ref ref="STDOUT" />
52
53function lotate {
54logfile=$1
55nr_max=$2
56if [ -f $logfile ]; then
57for i in `seq $(expr 10 - 1) -1 1`; do
58if [ -f ${logfile}.${i} ]; then
59mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
60fi
61done
62mv $logfile $logfile.1
63fi
64}
65
66function start {
67 if [ ! -d ${LOGDIR} ]; then
68 mkdir -p ${LOGDIR}
69 fi
70 # Backup log files
71 for log in ${LOGS}; do
72 echo "rotate log: $log"
73 if [ -f ${log} ]; then
74 lotate ${log}
75 fi
76 done
77
78 # Run floodlight
79 echo "Starting ONOS controller ..."
80 echo
81 java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -Xbootclasspath/a:$CLASSPATH -jar ${FL_JAR} -cf ./onos.properties > /dev/null 2>&1 &
82 sudo tcpdump -n -i eth0 'tcp port 6633' -s0 -w ${PCAP_LOG} &
83}
84
85function stop {
86 # Kill the existing processes
87 flpid=`ps -edalf |grep java |grep logback.xml | awk '{print $4}'`
88 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
89 pids="$flpid $tdpid"
90 for p in ${pids}; do
91 if [ x$p != "x" ]; then
92 sudo kill -KILL $p
93 echo "Killed existing prosess (pid: $p)"
94 fi
95 done
96}
97
98case "$1" in
99 start)
100 stop
101 start
102 ;;
103 stop)
104 stop
105 ;;
106 status)
107 n=`ps -edalf |grep java |grep logback.xml | wc -l`
108 echo "$n instance of onos running"
109 ;;
110 *)
111 echo "Usage: $0 {start|stop|restart|status}"
112 exit 1
113esac