blob: fa6bb3a6580c040dc54bd222f42e0a51f5a792a5 [file] [log] [blame]
Pankaj Berde1b399bb2013-06-12 11:04:11 -07001#!/bin/bash
2
3# Set paths
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -07004ONOS_HOME=`dirname $0`
5ONOS_JAR="${ONOS_HOME}/target/floodlight.jar"
6ONOS_ONLY_JAR="${ONOS_HOME}/target/floodlight-only.jar"
7ONOS_LOGBACK="${ONOS_HOME}/logback.xml"
8LOGDIR=${ONOS_HOME}/onos-logs
9ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
Pankaj Berde1b399bb2013-06-12 11:04:11 -070010PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap"
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070011LOGS="$ONOS_LOG $PCAP_LOG"
Pankaj Berde1b399bb2013-06-12 11:04:11 -070012
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
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070027#CLASSPATH=`echo ${ONOS_HOME}/lib/*.jar ${ONOS_HOME}/lib/titan/*.jar | sed 's/ /:/g'`
28CLASSPATH="${ONOS_ONLY_JAR}:${ONOS_HOME}/lib/*:${ONOS_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
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070063 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Pankaj Berde1b399bb2013-06-12 11:04:11 -070064<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">
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070072<file>${ONOS_LOG}</file>
Pankaj Berde1b399bb2013-06-12 11:04:11 -070073<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
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -070091 #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ${ONOS_HOME}/onos.properties > /dev/null 2>&1 &
92 #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${CLASSPATH} ${MAIN_CLASS} -cf ${ONOS_HOME}/onos.properties > /dev/n
Pankaj Berde1b399bb2013-06-12 11:04:11 -070093
Masayoshi Kobayashia8e38352013-06-20 16:52:40 -070094 ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_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
Masayoshi Kobayashi056cd472013-06-20 16:47:14 -0700110# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
Pankaj Berde1b399bb2013-06-12 11:04:11 -0700111# 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