blob: 012a994de4162ad68aa5563308ead43d97a57caf [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"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000043
44<root level="DEBUG">
45<appender-ref ref="FILE" />
46</root>
47</configuration>
48EOF_LOGBACK
49
admin6bdc9992013-02-06 11:06:02 -080050#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000051#<appender-ref ref="STDOUT" />
52
53function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000054 logfile=$1
55 nr_max=${2:-10}
56 if [ -f $logfile ]; then
57 for i in `seq $(expr $nr_max - 1) -1 1`; do
58 if [ -f ${logfile}.${i} ]; then
59 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
60 fi
61 done
62 mv $logfile $logfile.1
63 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000064}
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
Masayoshi Kobayashi45dcdad2013-03-13 22:55:36 +000081 java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ${FL_HOME}/onos.properties > /dev/null 2>&1 &
Ubuntuaea2a682013-02-08 08:30:10 +000082# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
Ubuntu787c3ad2013-02-07 07:38:24 +000083 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 +000084}
85
86function stop {
87 # Kill the existing processes
88 flpid=`ps -edalf |grep java |grep logback.xml | awk '{print $4}'`
89 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
90 pids="$flpid $tdpid"
91 for p in ${pids}; do
92 if [ x$p != "x" ]; then
93 sudo kill -KILL $p
94 echo "Killed existing prosess (pid: $p)"
95 fi
96 done
97}
98
admin6bdc9992013-02-06 11:06:02 -080099function deldb {
100 # Delete the berkeley db database
101 if [ -d "/tmp/cassandra.titan" ]; then
102 rm -rf /tmp/cassandra.titan
103 mkdir /tmp/cassandra.titan
104 fi
105}
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000106function check_db {
107 if [ -d "/tmp/cassandra.titan" ]; then
108 echo "Cassandra is running on local berkely db. Exitting"
109 exit
110 fi
111 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000112 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000113 echo "Cassandra is not running. Exitting"
114 exit
115 fi
116}
admin6bdc9992013-02-06 11:06:02 -0800117
Ubuntu08edc7a2013-01-30 17:59:19 +0000118case "$1" in
119 start)
120 stop
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000121 check_db
Ubuntu08edc7a2013-01-30 17:59:19 +0000122 start
123 ;;
124 stop)
125 stop
126 ;;
admin6bdc9992013-02-06 11:06:02 -0800127 deldb)
128 deldb
129 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000130 status)
131 n=`ps -edalf |grep java |grep logback.xml | wc -l`
132 echo "$n instance of onos running"
133 ;;
134 *)
135 echo "Usage: $0 {start|stop|restart|status}"
136 exit 1
137esac