blob: 58f04b8d41fbefbdc37d6f8878656ad3b88871ed [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=""
15#JVM_OPTS="$JVM_OPTS -server -d64"
16#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
17#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
18#JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
19#JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
20#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/*"
25MAIN_CLASS="net.floodlightcontroller.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 &
85 java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -cp ${CLASSPATH} ${MAIN_CLASS} -cf ${FL_HOME}/onos.properties > /dev/null 2>&1 &
86
87
Ubuntuaea2a682013-02-08 08:30:10 +000088# 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 +000089# 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 +000090}
91
92function stop {
93 # Kill the existing processes
94 flpid=`ps -edalf |grep java |grep logback.xml | awk '{print $4}'`
95 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
96 pids="$flpid $tdpid"
97 for p in ${pids}; do
98 if [ x$p != "x" ]; then
Pavlin Radoslavovb531d712013-03-29 15:13:43 -070099 kill -KILL $p
Ubuntu08edc7a2013-01-30 17:59:19 +0000100 echo "Killed existing prosess (pid: $p)"
101 fi
102 done
103}
104
admin6bdc9992013-02-06 11:06:02 -0800105function deldb {
106 # Delete the berkeley db database
107 if [ -d "/tmp/cassandra.titan" ]; then
108 rm -rf /tmp/cassandra.titan
109 mkdir /tmp/cassandra.titan
110 fi
111}
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000112function check_db {
113 if [ -d "/tmp/cassandra.titan" ]; then
114 echo "Cassandra is running on local berkely db. Exitting"
115 exit
116 fi
117 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000118 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000119 echo "Cassandra is not running. Exitting"
120 exit
121 fi
122}
admin6bdc9992013-02-06 11:06:02 -0800123
Ubuntu08edc7a2013-01-30 17:59:19 +0000124case "$1" in
125 start)
126 stop
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000127 check_db
Ubuntu08edc7a2013-01-30 17:59:19 +0000128 start
129 ;;
130 stop)
131 stop
132 ;;
admin6bdc9992013-02-06 11:06:02 -0800133 deldb)
134 deldb
135 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000136 status)
137 n=`ps -edalf |grep java |grep logback.xml | wc -l`
138 echo "$n instance of onos running"
139 ;;
140 *)
141 echo "Usage: $0 {start|stop|restart|status}"
142 exit 1
143esac