Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Set paths |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 4 | if [ -z "${ONOS_HOME}" ]; then |
| 5 | ONOS_HOME=`dirname $0` |
| 6 | fi |
Masayoshi Kobayashi | 9973090 | 2013-06-27 23:23:20 -0700 | [diff] [blame] | 7 | |
Masayoshi Kobayashi | 93bf605 | 2013-07-12 13:06:56 -0700 | [diff] [blame] | 8 | ## Because the script change dir to $ONOS_HOME, we can set ONOS_LOGBACK and LOGDIR relative to $ONOS_HOME |
| 9 | #ONOS_LOGBACK="${ONOS_HOME}/logback.`hostname`.xml" |
| 10 | #LOGDIR=${ONOS_HOME}/onos-logs |
| 11 | ONOS_LOGBACK="./logback.`hostname`.xml" |
| 12 | LOGDIR=./onos-logs |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 13 | ONOS_LOG="${LOGDIR}/onos.`hostname`.log" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 14 | PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap" |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 15 | LOGS="$ONOS_LOG $PCAP_LOG" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 16 | |
| 17 | # Set JVM options |
| 18 | JVM_OPTS="" |
timlindberg | 8b13e70 | 2013-07-17 14:45:50 -0700 | [diff] [blame] | 19 | ## If you want JaCoCo Code Coverage reports... uncomment line below |
| 20 | 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] | 21 | JVM_OPTS="$JVM_OPTS -server -d64" |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 22 | #JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m" |
| 23 | JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m" |
| 24 | #JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
Pankaj Berde | ff1fe03 | 2013-06-27 14:59:00 -0700 | [diff] [blame] | 25 | JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
Jonathan Hart | f756278 | 2013-04-03 19:50:36 -0700 | [diff] [blame] | 26 | JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192" |
| 27 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8" |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 28 | JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 29 | #JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false" |
Pankaj Berde | ff1fe03 | 2013-06-27 14:59:00 -0700 | [diff] [blame] | 30 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \ |
| 31 | -XX:+UseThreadPriorities \ |
| 32 | -XX:ThreadPriorityPolicy=42 \ |
| 33 | -XX:+UseCompressedOops \ |
| 34 | -Dcom.sun.management.jmxremote.port=7189 \ |
| 35 | -Dcom.sun.management.jmxremote.ssl=false \ |
| 36 | -Dcom.sun.management.jmxremote.authenticate=false" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 37 | |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 38 | # Set ONOS core main class |
HIGUCHI Yuta | 49cf4d2 | 2013-06-17 12:15:17 -0700 | [diff] [blame] | 39 | MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 40 | |
HIGUCHI Yuta | 88f3bf3 | 2013-06-20 10:37:47 -0700 | [diff] [blame] | 41 | if [ -z "${MVN}" ]; then |
Masayoshi Kobayashi | 9973090 | 2013-06-27 23:23:20 -0700 | [diff] [blame] | 42 | MVN="mvn -o" |
HIGUCHI Yuta | 88f3bf3 | 2013-06-20 10:37:47 -0700 | [diff] [blame] | 43 | fi |
| 44 | |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 45 | #<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/> |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 46 | #<appender-ref ref="STDOUT" /> |
| 47 | |
| 48 | function lotate { |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 49 | logfile=$1 |
| 50 | nr_max=${2:-10} |
| 51 | if [ -f $logfile ]; then |
| 52 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 53 | if [ -f ${logfile}.${i} ]; then |
| 54 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 55 | fi |
| 56 | done |
| 57 | mv $logfile $logfile.1 |
| 58 | fi |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | function start { |
| 62 | if [ ! -d ${LOGDIR} ]; then |
| 63 | mkdir -p ${LOGDIR} |
| 64 | fi |
| 65 | # Backup log files |
| 66 | for log in ${LOGS}; do |
| 67 | echo "rotate log: $log" |
| 68 | if [ -f ${log} ]; then |
| 69 | lotate ${log} |
| 70 | fi |
| 71 | done |
| 72 | |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 73 | # Create a logback file if required |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 74 | cat <<EOF_LOGBACK >${ONOS_LOGBACK} |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 75 | <configuration scan="true" debug="true"> |
| 76 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| 77 | <encoder> |
| 78 | <pattern>%level [%logger:%thread] %msg%n</pattern> |
| 79 | </encoder> |
| 80 | </appender> |
| 81 | |
| 82 | <appender name="FILE" class="ch.qos.logback.core.FileAppender"> |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 83 | <file>${ONOS_LOG}</file> |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 84 | <encoder> |
| 85 | <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> |
| 86 | </encoder> |
| 87 | </appender> |
| 88 | |
| 89 | <logger name="org" level="WARN"/> |
| 90 | <logger name="LogService" level="WARN"/> <!-- Restlet access logging --> |
| 91 | <logger name="net.floodlightcontroller.logging" level="WARN"/> |
| 92 | |
| 93 | <root level="DEBUG"> |
| 94 | <appender-ref ref="FILE" /> |
| 95 | </root> |
| 96 | </configuration> |
| 97 | EOF_LOGBACK |
| 98 | |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 99 | # Run floodlight |
| 100 | echo "Starting ONOS controller ..." |
| 101 | echo |
Jonathan Hart | e4997b9 | 2013-03-22 09:57:41 -0700 | [diff] [blame] | 102 | |
Masayoshi Kobayashi | 9d06fc5 | 2013-06-20 23:05:30 -0700 | [diff] [blame] | 103 | # XXX : MVN has to run at the project top dir |
Masayoshi Kobayashi | 93bf605 | 2013-07-12 13:06:56 -0700 | [diff] [blame] | 104 | echo $ONOS_HOME |
Masayoshi Kobayashi | 9d06fc5 | 2013-06-20 23:05:30 -0700 | [diff] [blame] | 105 | cd ${ONOS_HOME} |
Masayoshi Kobayashi | 93bf605 | 2013-07-12 13:06:56 -0700 | [diff] [blame] | 106 | pwd |
| 107 | echo "${MVN} exec:exec -Dexec.executable=\"java\" -Dexec.args=\"${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ./conf/onos.properties\"" |
| 108 | |
| 109 | ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ./conf/onos.properties" > ${LOGDIR}/onos.`hostname`.stdout 2>${LOGDIR}/onos.`hostname`.stderr & |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 110 | |
| 111 | echo "Waiting for ONOS to start..." |
| 112 | COUNT=0 |
| 113 | ESTATE=0 |
| 114 | while [ "$COUNT" != "10" ]; do |
Masayoshi Kobayashi | 93bf605 | 2013-07-12 13:06:56 -0700 | [diff] [blame] | 115 | echo -n "." |
| 116 | sleep 1 |
| 117 | # COUNT=$((COUNT + 1)) |
| 118 | # sleep $COUNT |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 119 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 120 | if [ "$n" -ge "1" ]; then |
Masayoshi Kobayashi | 93bf605 | 2013-07-12 13:06:56 -0700 | [diff] [blame] | 121 | echo "" |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 122 | exit 0 |
| 123 | fi |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 124 | done |
| 125 | echo "Timed out" |
| 126 | exit 1 |
Jonathan Hart | e4997b9 | 2013-03-22 09:57:41 -0700 | [diff] [blame] | 127 | |
Masayoshi Kobayashi | 7ee83b3 | 2013-06-20 16:49:01 -0700 | [diff] [blame] | 128 | # 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] | 129 | # 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] | 130 | } |
| 131 | |
| 132 | function stop { |
| 133 | # Kill the existing processes |
Pankaj Berde | 77b5851 | 2013-04-05 12:06:37 -0700 | [diff] [blame] | 134 | flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'` |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 135 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 136 | pids="$flpid $tdpid" |
| 137 | for p in ${pids}; do |
| 138 | if [ x$p != "x" ]; then |
timlindberg | 8b13e70 | 2013-07-17 14:45:50 -0700 | [diff] [blame] | 139 | kill -TERM $p |
Pankaj Berde | f71f6cb | 2013-06-27 18:30:53 -0700 | [diff] [blame] | 140 | echo "Killed existing process (pid: $p)" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 141 | fi |
| 142 | done |
| 143 | } |
| 144 | |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 145 | function check_db { |
| 146 | if [ -d "/tmp/cassandra.titan" ]; then |
| 147 | echo "Cassandra is running on local berkely db. Exitting" |
| 148 | exit |
| 149 | fi |
| 150 | n=`ps -edalf |grep java |grep apache-cassandra | wc -l` |
Masayoshi Kobayashi | e772c7c | 2013-02-28 00:36:33 +0000 | [diff] [blame] | 151 | if [ x$n == "x0" ]; then |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 152 | echo "Cassandra is not running. Exitting" |
| 153 | exit |
| 154 | fi |
| 155 | } |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 156 | |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 157 | case "$1" in |
| 158 | start) |
| 159 | stop |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 160 | check_db |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 161 | start |
| 162 | ;; |
Masayoshi Kobayashi | 05f9fc9 | 2013-04-12 17:18:22 +0000 | [diff] [blame] | 163 | startifdown) |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 164 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Masayoshi Kobayashi | 05f9fc9 | 2013-04-12 17:18:22 +0000 | [diff] [blame] | 165 | if [ $n == 0 ]; then |
| 166 | start |
| 167 | else |
| 168 | echo "$n instance of onos running" |
| 169 | fi |
| 170 | ;; |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 171 | stop) |
| 172 | stop |
| 173 | ;; |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 174 | status) |
HIGUCHI Yuta | e7aa925 | 2013-06-06 14:54:21 -0700 | [diff] [blame] | 175 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 176 | echo "$n instance of onos running" |
| 177 | ;; |
| 178 | *) |
Masayoshi Kobayashi | 05f9fc9 | 2013-04-12 17:18:22 +0000 | [diff] [blame] | 179 | echo "Usage: $0 {start|stop|restart|status|startifdown}" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 180 | exit 1 |
| 181 | esac |