blob: 83819d79b0aec42062dafe738a749936f5d331bc [file] [log] [blame]
Ubuntu08edc7a2013-01-30 17:59:19 +00001#!/bin/bash
Yuta HIGUCHIa7ec0732014-03-10 16:01:06 -07002
Naoki Shiota4e463182014-03-21 15:13:24 -07003echo
4echo "===================================================================="
5echo "[WARNING] This script is deprecated. Use \"\$ ./onos.sh core\" instead."
6echo "===================================================================="
7echo
8
yoshid76fa1f2013-12-19 14:20:34 -08009ulimit -c unlimited
Ubuntu08edc7a2013-01-30 17:59:19 +000010
11# Set paths
Bob Lantzc7c05402013-12-16 21:22:12 -080012ONOS_HOME="${ONOS_HOME:-`dirname $0`}"
Yuta HIGUCHIa7ec0732014-03-10 16:01:06 -070013RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud}
14RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master}
15
16export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${ONOS_HOME}/lib:${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}
Masayoshi Kobayashi99730902013-06-27 23:23:20 -070017
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -070018## Because the script change dir to $ONOS_HOME, we can set ONOS_LOGBACK and LOGDIR relative to $ONOS_HOME
Bob Lantzc7c05402013-12-16 21:22:12 -080019ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_HOME}/logback.`hostname`.xml}
20LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
Bob Lantz63bbe4c2014-02-06 19:29:55 -080021LOGBASE=${ONOS_LOGBASE:-onos.`hostname`}
22ONOS_LOG="${LOGDIR}/${LOGBASE}.log"
23PCAP_LOG="${LOGDIR}/${LOGBASE}.pcap"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070024LOGS="$ONOS_LOG $PCAP_LOG"
Ubuntu08edc7a2013-01-30 17:59:19 +000025
Bob Lantzf89714c2013-12-17 12:35:05 -080026ONOS_PROPS=${ONOS_PROPS:-${ONOS_HOME}/conf/onos.properties}
27JMX_PORT=${JMX_PORT:-7189}
Bob Lantzc7c05402013-12-16 21:22:12 -080028
Ubuntu08edc7a2013-01-30 17:59:19 +000029# Set JVM options
Bob Lantzc7c05402013-12-16 21:22:12 -080030JVM_OPTS="${JVM_OPTS:-}"
timlindberg8b13e702013-07-17 14:45:50 -070031## If you want JaCoCo Code Coverage reports... uncomment line below
mininet4a828f22013-12-10 14:22:39 -080032#JVM_OPTS="$JVM_OPTS -javaagent:${ONOS_HOME}/lib/jacocoagent.jar=dumponexit=true,output=file,destfile=${LOGDIR}/jacoco.exec"
Jonathan Hartf7562782013-04-03 19:50:36 -070033JVM_OPTS="$JVM_OPTS -server -d64"
Yuta HIGUCHI37f8b7d2014-01-20 09:43:19 -080034#JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m"
yoshid76fa1f2013-12-19 14:20:34 -080035JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070036#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
yoshid76fa1f2013-12-19 14:20:34 -080037#JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070038#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070039JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
Jonathan Hartf7562782013-04-03 19:50:36 -070040JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
41JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -070042JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
Ubuntu08edc7a2013-01-30 17:59:19 +000043#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
Pankaj Berdeff1fe032013-06-27 14:59:00 -070044JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
45 -XX:+UseThreadPriorities \
46 -XX:ThreadPriorityPolicy=42 \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070047 -XX:+UseCompressedOops \
Bob Lantzc7c05402013-12-16 21:22:12 -080048 -Dcom.sun.management.jmxremote.port=$JMX_PORT \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070049 -Dcom.sun.management.jmxremote.ssl=false \
yoshid76fa1f2013-12-19 14:20:34 -080050 -Dbenchmark.measureBP=0 \
51 -Dbenchmark.measureRc=0 \
52 -Dbenchmark.measureONOS=0 \
Pavlin Radoslavov8709f482013-10-15 02:10:41 -070053 -Dcom.sun.management.jmxremote.authenticate=false"
Pavlin Radoslavova56fb322013-10-16 03:05:58 -070054JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j"
Ubuntu08edc7a2013-01-30 17:59:19 +000055
Pankaj Berdebbd38612013-06-22 05:59:12 -070056# Set ONOS core main class
Jonathan Hart51f6f5b2014-04-03 10:32:10 -070057MAIN_CLASS="net.onrc.onos.core.main.Main"
Ubuntu08edc7a2013-01-30 17:59:19 +000058
Bob Lantz20612522013-12-17 00:30:54 -080059MVN=${MVN:-mvn -o}
HIGUCHI Yuta88f3bf32013-06-20 10:37:47 -070060
Yuta HIGUCHIfbd9a7e2014-03-23 00:18:50 -070061CPFILE=${ONOS_HOME}/.javacp.`hostname`
62if [ ! -f ${CPFILE} ]; then
Yuta HIGUCHIb561efa2013-12-20 01:35:04 -080063 ${MVN} -f ${ONOS_HOME}/pom.xml compile
64fi
Yuta HIGUCHIfbd9a7e2014-03-23 00:18:50 -070065JAVA_CP=`cat ${CPFILE}`
Yuta HIGUCHI6e4eca52013-12-20 09:12:20 -080066JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes"
Yuta HIGUCHIb561efa2013-12-20 01:35:04 -080067
admin6bdc9992013-02-06 11:06:02 -080068#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
Ubuntu08edc7a2013-01-30 17:59:19 +000069#<appender-ref ref="STDOUT" />
70
71function lotate {
Masayoshi Kobayashi274c07d2013-02-20 21:38:16 +000072 logfile=$1
73 nr_max=${2:-10}
74 if [ -f $logfile ]; then
75 for i in `seq $(expr $nr_max - 1) -1 1`; do
76 if [ -f ${logfile}.${i} ]; then
77 mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
78 fi
79 done
80 mv $logfile $logfile.1
81 fi
Ubuntu08edc7a2013-01-30 17:59:19 +000082}
83
84function start {
85 if [ ! -d ${LOGDIR} ]; then
86 mkdir -p ${LOGDIR}
87 fi
88 # Backup log files
89 for log in ${LOGS}; do
90 echo "rotate log: $log"
91 if [ -f ${log} ]; then
92 lotate ${log}
93 fi
94 done
95
Jonathan Hart0ae27772013-03-19 13:03:52 -070096# Create a logback file if required
Jonathan Hartb5ad4612013-09-27 14:47:25 +120097 if [ ! -f ${ONOS_LOGBACK} ]; then
98 cat <<EOF_LOGBACK >${ONOS_LOGBACK}
Yuta HIGUCHI51e5f302014-01-06 16:28:51 -080099<configuration scan="true" scanPeriod="1 minutes" debug="true">
Jonathan Hart0ae27772013-03-19 13:03:52 -0700100<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
101<encoder>
102<pattern>%level [%logger:%thread] %msg%n</pattern>
103</encoder>
104</appender>
105
106<appender name="FILE" class="ch.qos.logback.core.FileAppender">
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -0700107<file>${ONOS_LOG}</file>
Jonathan Hart0ae27772013-03-19 13:03:52 -0700108<encoder>
109<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
Yuta HIGUCHI51e5f302014-01-06 16:28:51 -0800110<immediateFlush>true</immediateFlush>
Jonathan Hart0ae27772013-03-19 13:03:52 -0700111</encoder>
112</appender>
113
114<logger name="org" level="WARN"/>
115<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
116<logger name="net.floodlightcontroller.logging" level="WARN"/>
Jonathan Hart64a036d2014-01-15 10:58:01 -0800117<logger name="com.thinkaurelius.titan" level="INFO"/>
Jonathan Hart0ae27772013-03-19 13:03:52 -0700118
119<root level="DEBUG">
120<appender-ref ref="FILE" />
121</root>
122</configuration>
123EOF_LOGBACK
Jonathan Hartb5ad4612013-09-27 14:47:25 +1200124 fi
Jonathan Hart0ae27772013-03-19 13:03:52 -0700125
Yuta HIGUCHI4fb214c2013-12-10 14:56:52 -0800126 # Run ONOS
Ubuntu08edc7a2013-01-30 17:59:19 +0000127 echo "Starting ONOS controller ..."
Bob Lantzc7c05402013-12-16 21:22:12 -0800128 echo
Jonathan Harte4997b92013-03-22 09:57:41 -0700129
Bob Lantzc7c05402013-12-16 21:22:12 -0800130 # XXX : MVN has to run at the project top dir
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700131 echo $ONOS_HOME
Masayoshi Kobayashi9d06fc52013-06-20 23:05:30 -0700132 cd ${ONOS_HOME}
Bob Lantzc7c05402013-12-16 21:22:12 -0800133 pwd
Bob Lantz63bbe4c2014-02-06 19:29:55 -0800134 java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr &
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700135
136 echo "Waiting for ONOS to start..."
137 COUNT=0
138 ESTATE=0
139 while [ "$COUNT" != "10" ]; do
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700140 echo -n "."
141 sleep 1
142# COUNT=$((COUNT + 1))
143# sleep $COUNT
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700144 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
145 if [ "$n" -ge "1" ]; then
Masayoshi Kobayashi93bf6052013-07-12 13:06:56 -0700146 echo ""
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700147 exit 0
148 fi
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700149 done
150 echo "Timed out"
151 exit 1
Jonathan Harte4997b92013-03-22 09:57:41 -0700152
Masayoshi Kobayashi7ee83b32013-06-20 16:49:01 -0700153# 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 +0000154# 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 +0000155}
156
157function stop {
158 # Kill the existing processes
Pankaj Berde77b58512013-04-05 12:06:37 -0700159 flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
Ubuntu08edc7a2013-01-30 17:59:19 +0000160 tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
161 pids="$flpid $tdpid"
162 for p in ${pids}; do
163 if [ x$p != "x" ]; then
timlindberg8b13e702013-07-17 14:45:50 -0700164 kill -TERM $p
Pankaj Berdef71f6cb2013-06-27 18:30:53 -0700165 echo "Killed existing process (pid: $p)"
Ubuntu08edc7a2013-01-30 17:59:19 +0000166 fi
167 done
168}
169
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000170function check_db {
171 if [ -d "/tmp/cassandra.titan" ]; then
172 echo "Cassandra is running on local berkely db. Exitting"
173 exit
174 fi
175 n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
Masayoshi Kobayashie772c7c2013-02-28 00:36:33 +0000176 if [ x$n == "x0" ]; then
Masayoshi Kobayashicbd5e0a2013-02-25 19:00:19 +0000177 echo "Cassandra is not running. Exitting"
178 exit
179 fi
180}
admin6bdc9992013-02-06 11:06:02 -0800181
Ubuntu08edc7a2013-01-30 17:59:19 +0000182case "$1" in
183 start)
184 stop
yoshid76fa1f2013-12-19 14:20:34 -0800185# check_db
Bob Lantzc7c05402013-12-16 21:22:12 -0800186 start
187 ;;
188 startnokill)
Bob Lantz63bbe4c2014-02-06 19:29:55 -0800189# check_db
Bob Lantzc7c05402013-12-16 21:22:12 -0800190 start
Ubuntu08edc7a2013-01-30 17:59:19 +0000191 ;;
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000192 startifdown)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700193 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000194 if [ $n == 0 ]; then
195 start
Bob Lantzc7c05402013-12-16 21:22:12 -0800196 else
Masayoshi Kobayashi05f9fc92013-04-12 17:18:22 +0000197 echo "$n instance of onos running"
198 fi
199 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000200 stop)
201 stop
202 ;;
Ubuntu08edc7a2013-01-30 17:59:19 +0000203 status)
HIGUCHI Yutae7aa9252013-06-06 14:54:21 -0700204 n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
Ubuntu08edc7a2013-01-30 17:59:19 +0000205 echo "$n instance of onos running"
206 ;;
207 *)
Yuta HIGUCHI645a6682014-01-02 11:10:12 -0800208 echo "Usage: $0 {start|stop|status|startifdown}"
Ubuntu08edc7a2013-01-30 17:59:19 +0000209 exit 1
210esac