Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 1 | #!/bin/bash |
Yuta HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 2 | |
Naoki Shiota | 4e46318 | 2014-03-21 15:13:24 -0700 | [diff] [blame] | 3 | echo |
| 4 | echo "====================================================================" |
| 5 | echo "[WARNING] This script is deprecated. Use \"\$ ./onos.sh core\" instead." |
| 6 | echo "====================================================================" |
| 7 | echo |
| 8 | |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 9 | ulimit -c unlimited |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 10 | |
| 11 | # Set paths |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 12 | ONOS_HOME="${ONOS_HOME:-`dirname $0`}" |
Yuta HIGUCHI | a7ec073 | 2014-03-10 16:01:06 -0700 | [diff] [blame] | 13 | RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud} |
| 14 | RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master} |
| 15 | |
| 16 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${ONOS_HOME}/lib:${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH} |
Masayoshi Kobayashi | 9973090 | 2013-06-27 23:23:20 -0700 | [diff] [blame] | 17 | |
Masayoshi Kobayashi | 93bf605 | 2013-07-12 13:06:56 -0700 | [diff] [blame] | 18 | ## Because the script change dir to $ONOS_HOME, we can set ONOS_LOGBACK and LOGDIR relative to $ONOS_HOME |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 19 | ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_HOME}/logback.`hostname`.xml} |
| 20 | LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs} |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 21 | LOGBASE=${ONOS_LOGBASE:-onos.`hostname`} |
| 22 | ONOS_LOG="${LOGDIR}/${LOGBASE}.log" |
| 23 | PCAP_LOG="${LOGDIR}/${LOGBASE}.pcap" |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 24 | LOGS="$ONOS_LOG $PCAP_LOG" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 25 | |
Bob Lantz | f89714c | 2013-12-17 12:35:05 -0800 | [diff] [blame] | 26 | ONOS_PROPS=${ONOS_PROPS:-${ONOS_HOME}/conf/onos.properties} |
| 27 | JMX_PORT=${JMX_PORT:-7189} |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 28 | |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 29 | # Set JVM options |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 30 | JVM_OPTS="${JVM_OPTS:-}" |
timlindberg | 8b13e70 | 2013-07-17 14:45:50 -0700 | [diff] [blame] | 31 | ## If you want JaCoCo Code Coverage reports... uncomment line below |
mininet | 4a828f2 | 2013-12-10 14:22:39 -0800 | [diff] [blame] | 32 | #JVM_OPTS="$JVM_OPTS -javaagent:${ONOS_HOME}/lib/jacocoagent.jar=dumponexit=true,output=file,destfile=${LOGDIR}/jacoco.exec" |
Jonathan Hart | f756278 | 2013-04-03 19:50:36 -0700 | [diff] [blame] | 33 | JVM_OPTS="$JVM_OPTS -server -d64" |
Yuta HIGUCHI | 37f8b7d | 2014-01-20 09:43:19 -0800 | [diff] [blame] | 34 | #JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m" |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 35 | JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m" |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 36 | #JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m" |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 37 | #JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m" |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 38 | #JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
Pankaj Berde | ff1fe03 | 2013-06-27 14:59:00 -0700 | [diff] [blame] | 39 | JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
Jonathan Hart | f756278 | 2013-04-03 19:50:36 -0700 | [diff] [blame] | 40 | JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192" |
| 41 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8" |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 42 | JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 43 | #JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false" |
Pankaj Berde | ff1fe03 | 2013-06-27 14:59:00 -0700 | [diff] [blame] | 44 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \ |
| 45 | -XX:+UseThreadPriorities \ |
| 46 | -XX:ThreadPriorityPolicy=42 \ |
Pavlin Radoslavov | 8709f48 | 2013-10-15 02:10:41 -0700 | [diff] [blame] | 47 | -XX:+UseCompressedOops \ |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 48 | -Dcom.sun.management.jmxremote.port=$JMX_PORT \ |
Pavlin Radoslavov | 8709f48 | 2013-10-15 02:10:41 -0700 | [diff] [blame] | 49 | -Dcom.sun.management.jmxremote.ssl=false \ |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 50 | -Dbenchmark.measureBP=0 \ |
| 51 | -Dbenchmark.measureRc=0 \ |
| 52 | -Dbenchmark.measureONOS=0 \ |
Pavlin Radoslavov | 8709f48 | 2013-10-15 02:10:41 -0700 | [diff] [blame] | 53 | -Dcom.sun.management.jmxremote.authenticate=false" |
Pavlin Radoslavov | a56fb32 | 2013-10-16 03:05:58 -0700 | [diff] [blame] | 54 | JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 55 | |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 56 | # Set ONOS core main class |
Jonathan Hart | 51f6f5b | 2014-04-03 10:32:10 -0700 | [diff] [blame] | 57 | MAIN_CLASS="net.onrc.onos.core.main.Main" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 58 | |
Bob Lantz | 2061252 | 2013-12-17 00:30:54 -0800 | [diff] [blame] | 59 | MVN=${MVN:-mvn -o} |
HIGUCHI Yuta | 88f3bf3 | 2013-06-20 10:37:47 -0700 | [diff] [blame] | 60 | |
Yuta HIGUCHI | fbd9a7e | 2014-03-23 00:18:50 -0700 | [diff] [blame] | 61 | CPFILE=${ONOS_HOME}/.javacp.`hostname` |
| 62 | if [ ! -f ${CPFILE} ]; then |
Yuta HIGUCHI | b561efa | 2013-12-20 01:35:04 -0800 | [diff] [blame] | 63 | ${MVN} -f ${ONOS_HOME}/pom.xml compile |
| 64 | fi |
Yuta HIGUCHI | fbd9a7e | 2014-03-23 00:18:50 -0700 | [diff] [blame] | 65 | JAVA_CP=`cat ${CPFILE}` |
Yuta HIGUCHI | 6e4eca5 | 2013-12-20 09:12:20 -0800 | [diff] [blame] | 66 | JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes" |
Yuta HIGUCHI | b561efa | 2013-12-20 01:35:04 -0800 | [diff] [blame] | 67 | |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 68 | #<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/> |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 69 | #<appender-ref ref="STDOUT" /> |
| 70 | |
| 71 | function lotate { |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 72 | 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 |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | function 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 Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 96 | # Create a logback file if required |
Jonathan Hart | b5ad461 | 2013-09-27 14:47:25 +1200 | [diff] [blame] | 97 | if [ ! -f ${ONOS_LOGBACK} ]; then |
| 98 | cat <<EOF_LOGBACK >${ONOS_LOGBACK} |
Yuta HIGUCHI | 51e5f30 | 2014-01-06 16:28:51 -0800 | [diff] [blame] | 99 | <configuration scan="true" scanPeriod="1 minutes" debug="true"> |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 100 | <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 Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 107 | <file>${ONOS_LOG}</file> |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 108 | <encoder> |
| 109 | <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> |
Yuta HIGUCHI | 51e5f30 | 2014-01-06 16:28:51 -0800 | [diff] [blame] | 110 | <immediateFlush>true</immediateFlush> |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 111 | </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 Hart | 64a036d | 2014-01-15 10:58:01 -0800 | [diff] [blame] | 117 | <logger name="com.thinkaurelius.titan" level="INFO"/> |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 118 | |
| 119 | <root level="DEBUG"> |
| 120 | <appender-ref ref="FILE" /> |
| 121 | </root> |
| 122 | </configuration> |
| 123 | EOF_LOGBACK |
Jonathan Hart | b5ad461 | 2013-09-27 14:47:25 +1200 | [diff] [blame] | 124 | fi |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 125 | |
Yuta HIGUCHI | 4fb214c | 2013-12-10 14:56:52 -0800 | [diff] [blame] | 126 | # Run ONOS |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 127 | echo "Starting ONOS controller ..." |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 128 | echo |
Jonathan Hart | e4997b9 | 2013-03-22 09:57:41 -0700 | [diff] [blame] | 129 | |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 130 | # XXX : MVN has to run at the project top dir |
Masayoshi Kobayashi | 93bf605 | 2013-07-12 13:06:56 -0700 | [diff] [blame] | 131 | echo $ONOS_HOME |
Masayoshi Kobayashi | 9d06fc5 | 2013-06-20 23:05:30 -0700 | [diff] [blame] | 132 | cd ${ONOS_HOME} |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 133 | pwd |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 134 | java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr & |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 135 | |
| 136 | echo "Waiting for ONOS to start..." |
| 137 | COUNT=0 |
| 138 | ESTATE=0 |
| 139 | while [ "$COUNT" != "10" ]; do |
Masayoshi Kobayashi | 93bf605 | 2013-07-12 13:06:56 -0700 | [diff] [blame] | 140 | echo -n "." |
| 141 | sleep 1 |
| 142 | # COUNT=$((COUNT + 1)) |
| 143 | # sleep $COUNT |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 144 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 145 | if [ "$n" -ge "1" ]; then |
Masayoshi Kobayashi | 93bf605 | 2013-07-12 13:06:56 -0700 | [diff] [blame] | 146 | echo "" |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 147 | exit 0 |
| 148 | fi |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 149 | done |
| 150 | echo "Timed out" |
| 151 | exit 1 |
Jonathan Hart | e4997b9 | 2013-03-22 09:57:41 -0700 | [diff] [blame] | 152 | |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 153 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
Masayoshi Kobayashi | 8849a66 | 2013-03-14 22:18:51 +0000 | [diff] [blame] | 154 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | function stop { |
| 158 | # Kill the existing processes |
Pankaj Berde | 77b5851 | 2013-04-05 12:06:37 -0700 | [diff] [blame] | 159 | flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'` |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 160 | 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 |
timlindberg | 8b13e70 | 2013-07-17 14:45:50 -0700 | [diff] [blame] | 164 | kill -TERM $p |
Pankaj Berde | f71f6cb | 2013-06-27 18:30:53 -0700 | [diff] [blame] | 165 | echo "Killed existing process (pid: $p)" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 166 | fi |
| 167 | done |
| 168 | } |
| 169 | |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 170 | function 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 Kobayashi | e772c7c | 2013-02-28 00:36:33 +0000 | [diff] [blame] | 176 | if [ x$n == "x0" ]; then |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 177 | echo "Cassandra is not running. Exitting" |
| 178 | exit |
| 179 | fi |
| 180 | } |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 181 | |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 182 | case "$1" in |
| 183 | start) |
| 184 | stop |
yoshi | d76fa1f | 2013-12-19 14:20:34 -0800 | [diff] [blame] | 185 | # check_db |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 186 | start |
| 187 | ;; |
| 188 | startnokill) |
Bob Lantz | 63bbe4c | 2014-02-06 19:29:55 -0800 | [diff] [blame] | 189 | # check_db |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 190 | start |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 191 | ;; |
Masayoshi Kobayashi | 05f9fc9 | 2013-04-12 17:18:22 +0000 | [diff] [blame] | 192 | startifdown) |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 193 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Masayoshi Kobayashi | 05f9fc9 | 2013-04-12 17:18:22 +0000 | [diff] [blame] | 194 | if [ $n == 0 ]; then |
| 195 | start |
Bob Lantz | c7c0540 | 2013-12-16 21:22:12 -0800 | [diff] [blame] | 196 | else |
Masayoshi Kobayashi | 05f9fc9 | 2013-04-12 17:18:22 +0000 | [diff] [blame] | 197 | echo "$n instance of onos running" |
| 198 | fi |
| 199 | ;; |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 200 | stop) |
| 201 | stop |
| 202 | ;; |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 203 | status) |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 204 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 205 | echo "$n instance of onos running" |
| 206 | ;; |
| 207 | *) |
Yuta HIGUCHI | 645a668 | 2014-01-02 11:10:12 -0800 | [diff] [blame] | 208 | echo "Usage: $0 {start|stop|status|startifdown}" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 209 | exit 1 |
| 210 | esac |