blob: 9e8d559d9b0195e9b5fd295b42b7e400c7ea4cf7 [file] [log] [blame]
Ubuntu08edc7a2013-01-30 17:59:19 +00001#!/bin/bash
2
3# Set paths
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -07004#ONOS_HOME=`dirname $0`
5ONOS_HOME=${HOME}/ONOS
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -07006ONOS_JAR="${ONOS_HOME}/target/floodlight.jar"
7ONOS_ONLY_JAR="${ONOS_HOME}/target/floodlight-only.jar"
8ONOS_LOGBACK="${ONOS_HOME}/logback.xml"
9LOGDIR=${ONOS_HOME}/onos-logs
10ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
Ubuntu08edc7a2013-01-30 17:59:19 +000011PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070012LOGS="$ONOS_LOG $PCAP_LOG"
Ubuntu08edc7a2013-01-30 17:59:19 +000013
14# Set JVM options
15JVM_OPTS=""
Jonathan Hartf7562782013-04-03 19:50:36 -070016JVM_OPTS="$JVM_OPTS -server -d64"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070017#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
18JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
19#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
20JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Jonathan Hartf7562782013-04-03 19:50:36 -070021JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
22JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070023JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
Ubuntu08edc7a2013-01-30 17:59:19 +000024#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
25
26# Set classpath to include titan libs
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -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"
Ubuntu08edc7a2013-01-30 17:59:19 +000030
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070031if [ -z "${MVN}" ]; then
32 MVN="mvn"
33fi
34
admin6bdc9992013-02-06 11:06:02 -080035#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000036#<appender-ref ref="STDOUT" />
37
38function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000039 logfile=$1
40 nr_max=${2:-10}
41 if [ -f $logfile ]; then
42 for i in `seq $(expr $nr_max - 1) -1 1`; do
43 if [ -f ${logfile}.${i} ]; then
44 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
45 fi
46 done
47 mv $logfile $logfile.1
48 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000049}
50
51function start {
52 if [ ! -d ${LOGDIR} ]; then
53 mkdir -p ${LOGDIR}
54 fi
55 # Backup log files
56 for log in ${LOGS}; do
57 echo "rotate log: $log"
58 if [ -f ${log} ]; then
59 lotate ${log}
60 fi
61 done
62
Jonathan Hart0ae27772013-03-19 13:03:52 -070063# Create a logback file if required
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070064 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Jonathan Hart0ae27772013-03-19 13:03:52 -070065<configuration scan="true" debug="true">
66<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
67<encoder>
68<pattern>%level [%logger:%thread] %msg%n</pattern>
69</encoder>
70</appender>
71
72<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070073<file>${ONOS_LOG}</file>
Jonathan Hart0ae27772013-03-19 13:03:52 -070074<encoder>
75<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
76</encoder>
77</appender>
78
79<logger name="org" level="WARN"/>
80<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
81<logger name="net.floodlightcontroller.logging" level="WARN"/>
82
83<root level="DEBUG">
84<appender-ref ref="FILE" />
85</root>
86</configuration>
87EOF_LOGBACK
88
Ubuntu08edc7a2013-01-30 17:59:19 +000089 # Run floodlight
90 echo "Starting ONOS controller ..."
91 echo
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070092 #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ${ONOS_HOME}/onos.properties > /dev/null 2>&1 &
93 #java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${CLASSPATH} ${MAIN_CLASS} -cf ${ONOS_HOME}/onos.properties > /dev/n
Jonathan Harte4997b92013-03-22 09:57:41 -070094
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -070095 # XXX : MVN has to run at the project top dir
96 cd ${ONOS_HOME}
Masayoshi Kobayashia8e38352013-06-20 16:52:40 -070097 ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos.properties" > ${LOGDIR}/onos.stdout 2>${LOGDIR}/onos.stderr &
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -070098
99 echo "Waiting for ONOS to start..."
100 COUNT=0
101 ESTATE=0
102 while [ "$COUNT" != "10" ]; do
103 COUNT=$((COUNT + 1))
104 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
105 if [ "$n" -ge "1" ]; then
106 exit 0
107 fi
108 sleep $COUNT
109 done
110 echo "Timed out"
111 exit 1
Jonathan Harte4997b92013-03-22 09:57:41 -0700112
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -0700113# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
Masayoshi Kobayashi8849a662013-03-14 22:18:51 +0000114# 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 +0000115}
116
117function stop {
118 # Kill the existing processes
Pankaj Berde77b58512013-04-05 12:06:37 -0700119 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
Ubuntu08edc7a2013-01-30 17:59:19 +0000120 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
121 pids="$flpid $tdpid"
122 for p in ${pids}; do
123 if [ x$p != "x" ]; then
Pavlin Radoslavovb531d712013-03-29 15:13:43 -0700124 kill -KILL $p
Ubuntu08edc7a2013-01-30 17:59:19 +0000125 echo "Killed existing prosess (pid: $p)"
126 fi
127 done
128}
129
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000130function check_db {
131 if [ -d "/tmp/cassandra.titan" ]; then
132 echo "Cassandra is running on local berkely db. Exitting"
133 exit
134 fi
135 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000136 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000137 echo "Cassandra is not running. Exitting"
138 exit
139 fi
140}
admin6bdc9992013-02-06 11:06:02 -0800141
Ubuntu08edc7a2013-01-30 17:59:19 +0000142case "$1" in
143 start)
144 stop
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000145 check_db
Ubuntu08edc7a2013-01-30 17:59:19 +0000146 start
147 ;;
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000148 startifdown)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700149 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000150 if [ $n == 0 ]; then
151 start
152 else
153 echo "$n instance of onos running"
154 fi
155 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000156 stop)
157 stop
158 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000159 status)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700160 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Ubuntu08edc7a2013-01-30 17:59:19 +0000161 echo "$n instance of onos running"
162 ;;
163 *)
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000164 echo "Usage: $0 {start|stop|restart|status|startifdown}"
Ubuntu08edc7a2013-01-30 17:59:19 +0000165 exit 1
166esac