blob: 46833db7d108bf0782fcc53f96bc586e1020014a [file] [log] [blame]
Ubuntu08edc7a2013-01-30 17:59:19 +00001#!/bin/bash
2
3# Set paths
Pankaj Berdebbd38612013-06-22 05:59:12 -07004if [ -z "${ONOS_HOME}" ]; then
5 ONOS_HOME=`dirname $0`
6fi
Masayoshi Kobayashi99730902013-06-27 23:23:20 -07007
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -07008ONOS_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
Pankaj Berdebbd38612013-06-22 05:59:12 -070026# Set ONOS core main class
HIGUCHI Yuta49cf4d22013-06-17 12:15:17 -070027MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
Ubuntu08edc7a2013-01-30 17:59:19 +000028
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070029if [ -z "${MVN}" ]; then
Masayoshi Kobayashi99730902013-06-27 23:23:20 -070030 MVN="mvn -o"
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070031fi
32
admin6bdc9992013-02-06 11:06:02 -080033#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000034#<appender-ref ref="STDOUT" />
35
36function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000037 logfile=$1
38 nr_max=${2:-10}
39 if [ -f $logfile ]; then
40 for i in `seq $(expr $nr_max - 1) -1 1`; do
41 if [ -f ${logfile}.${i} ]; then
42 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
43 fi
44 done
45 mv $logfile $logfile.1
46 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000047}
48
49function start {
50 if [ ! -d ${LOGDIR} ]; then
51 mkdir -p ${LOGDIR}
52 fi
53 # Backup log files
54 for log in ${LOGS}; do
55 echo "rotate log: $log"
56 if [ -f ${log} ]; then
57 lotate ${log}
58 fi
59 done
60
Jonathan Hart0ae27772013-03-19 13:03:52 -070061# Create a logback file if required
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070062 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Jonathan Hart0ae27772013-03-19 13:03:52 -070063<configuration scan="true" debug="true">
64<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
65<encoder>
66<pattern>%level [%logger:%thread] %msg%n</pattern>
67</encoder>
68</appender>
69
70<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070071<file>${ONOS_LOG}</file>
Jonathan Hart0ae27772013-03-19 13:03:52 -070072<encoder>
73<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
74</encoder>
75</appender>
76
77<logger name="org" level="WARN"/>
78<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
79<logger name="net.floodlightcontroller.logging" level="WARN"/>
80
81<root level="DEBUG">
82<appender-ref ref="FILE" />
83</root>
84</configuration>
85EOF_LOGBACK
86
Ubuntu08edc7a2013-01-30 17:59:19 +000087 # Run floodlight
88 echo "Starting ONOS controller ..."
89 echo
Jonathan Harte4997b92013-03-22 09:57:41 -070090
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -070091 # XXX : MVN has to run at the project top dir
92 cd ${ONOS_HOME}
Masayoshi Kobayashi99730902013-06-27 23:23:20 -070093 echo "${MVN} exec:exec -Dexec.executable=\"java\" -Dexec.args=\"${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos.properties\""
94 ${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.`hostname`.stdout 2>${LOGDIR}/onos.`hostname`.stderr &
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -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
Jonathan Harte4997b92013-03-22 09:57:41 -0700109
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -0700110# 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 +0000111# 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 +0000112}
113
114function stop {
115 # Kill the existing processes
Pankaj Berde77b58512013-04-05 12:06:37 -0700116 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
Ubuntu08edc7a2013-01-30 17:59:19 +0000117 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
Pavlin Radoslavovb531d712013-03-29 15:13:43 -0700121 kill -KILL $p
Ubuntu08edc7a2013-01-30 17:59:19 +0000122 echo "Killed existing prosess (pid: $p)"
123 fi
124 done
125}
126
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000127function check_db {
128 if [ -d "/tmp/cassandra.titan" ]; then
129 echo "Cassandra is running on local berkely db. Exitting"
130 exit
131 fi
132 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000133 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000134 echo "Cassandra is not running. Exitting"
135 exit
136 fi
137}
admin6bdc9992013-02-06 11:06:02 -0800138
Ubuntu08edc7a2013-01-30 17:59:19 +0000139case "$1" in
140 start)
141 stop
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000142 check_db
Ubuntu08edc7a2013-01-30 17:59:19 +0000143 start
144 ;;
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000145 startifdown)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700146 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000147 if [ $n == 0 ]; then
148 start
149 else
150 echo "$n instance of onos running"
151 fi
152 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000153 stop)
154 stop
155 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000156 status)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700157 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Ubuntu08edc7a2013-01-30 17:59:19 +0000158 echo "$n instance of onos running"
159 ;;
160 *)
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000161 echo "Usage: $0 {start|stop|restart|status|startifdown}"
Ubuntu08edc7a2013-01-30 17:59:19 +0000162 exit 1
163esac