Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [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 | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 7 | ONOS_LOGBACK="${ONOS_HOME}/logback.xml" |
| 8 | LOGDIR=${ONOS_HOME}/onos-logs |
| 9 | ONOS_LOG="${LOGDIR}/onos.`hostname`.log" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 10 | PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap" |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 11 | LOGS="$ONOS_LOG $PCAP_LOG" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 12 | |
| 13 | # Set JVM options |
| 14 | JVM_OPTS="" |
| 15 | JVM_OPTS="$JVM_OPTS -server -d64" |
| 16 | JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m" |
Pankaj Berde | ff1fe03 | 2013-06-27 14:59:00 -0700 | [diff] [blame] | 17 | #JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
| 18 | JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 19 | JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192" |
| 20 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \ |
Pankaj Berde | ff1fe03 | 2013-06-27 14:59:00 -0700 | [diff] [blame] | 21 | -XX:+UseThreadPriorities \ |
| 22 | -XX:ThreadPriorityPolicy=42 \ |
| 23 | -XX:+UseCompressedOops \ |
| 24 | -Dcassandra.compaction.priority=1 \ |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 25 | -Dcom.sun.management.jmxremote.port=7199 \ |
| 26 | -Dcom.sun.management.jmxremote.ssl=false \ |
| 27 | -Dcom.sun.management.jmxremote.authenticate=false" |
| 28 | |
| 29 | #JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false" |
| 30 | |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 31 | # Set Main class to start ONOS core |
HIGUCHI Yuta | 49cf4d2 | 2013-06-17 12:15:17 -0700 | [diff] [blame] | 32 | MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 33 | |
HIGUCHI Yuta | 88f3bf3 | 2013-06-20 10:37:47 -0700 | [diff] [blame] | 34 | if [ -z "${MVN}" ]; then |
| 35 | MVN="mvn" |
| 36 | fi |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 37 | #<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/> |
| 38 | #<appender-ref ref="STDOUT" /> |
| 39 | |
| 40 | function lotate { |
| 41 | logfile=$1 |
| 42 | nr_max=${2:-10} |
| 43 | if [ -f $logfile ]; then |
| 44 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 45 | if [ -f ${logfile}.${i} ]; then |
| 46 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 47 | fi |
| 48 | done |
| 49 | mv $logfile $logfile.1 |
| 50 | fi |
| 51 | } |
| 52 | |
| 53 | function start { |
| 54 | if [ ! -d ${LOGDIR} ]; then |
| 55 | mkdir -p ${LOGDIR} |
| 56 | fi |
| 57 | # Backup log files |
| 58 | for log in ${LOGS}; do |
| 59 | echo "rotate log: $log" |
| 60 | if [ -f ${log} ]; then |
| 61 | lotate ${log} |
| 62 | fi |
| 63 | done |
| 64 | |
| 65 | # Create a logback file if required |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 66 | cat <<EOF_LOGBACK >${ONOS_LOGBACK} |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 67 | <configuration scan="true" debug="true"> |
| 68 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| 69 | <encoder> |
| 70 | <pattern>%level [%logger:%thread] %msg%n</pattern> |
| 71 | </encoder> |
| 72 | </appender> |
| 73 | |
| 74 | <appender name="FILE" class="ch.qos.logback.core.FileAppender"> |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 75 | <file>${ONOS_LOG}</file> |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 76 | <encoder> |
| 77 | <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> |
| 78 | </encoder> |
| 79 | </appender> |
| 80 | |
| 81 | <logger name="org" level="WARN"/> |
| 82 | <logger name="LogService" level="WARN"/> <!-- Restlet access logging --> |
| 83 | <logger name="net.floodlightcontroller.logging" level="WARN"/> |
| 84 | |
| 85 | <root level="DEBUG"> |
| 86 | <appender-ref ref="FILE" /> |
| 87 | </root> |
| 88 | </configuration> |
| 89 | EOF_LOGBACK |
| 90 | |
| 91 | # Run floodlight |
| 92 | echo "Starting ONOS controller ..." |
| 93 | echo |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 94 | |
Masayoshi Kobayashi | 9d06fc5 | 2013-06-20 23:05:30 -0700 | [diff] [blame] | 95 | # XXX MVN has to run at the project top dir.. |
| 96 | cd ${ONOS_HOME} |
Masayoshi Kobayashi | a8e3835 | 2013-06-20 16:52:40 -0700 | [diff] [blame] | 97 | ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos-embedded.properties" > ${LOGDIR}/onos.stdout 2>${LOGDIR}/onos.stderr & |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 98 | |
| 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 |
| 112 | |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 113 | sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | function stop { |
| 117 | # Kill the existing processes |
| 118 | flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'` |
| 119 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 120 | pids="$flpid $tdpid" |
| 121 | for p in ${pids}; do |
| 122 | if [ x$p != "x" ]; then |
| 123 | kill -KILL $p |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 124 | echo "Killed existing process (pid: $p)" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 125 | fi |
| 126 | done |
| 127 | } |
| 128 | |
| 129 | function deldb { |
| 130 | # Delete the cassandra data |
| 131 | if [ -d "/tmp/cassandra" ]; then |
| 132 | rm -rf /tmp/cassandra/* |
| 133 | fi |
| 134 | } |
| 135 | |
| 136 | case "$1" in |
| 137 | start) |
| 138 | stop |
| 139 | start |
| 140 | ;; |
| 141 | startifdown) |
| 142 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 143 | if [ $n == 0 ]; then |
| 144 | start |
| 145 | else |
| 146 | echo "$n instance of onos running" |
| 147 | fi |
| 148 | ;; |
| 149 | stop) |
| 150 | stop |
| 151 | ;; |
| 152 | deldb) |
| 153 | deldb |
| 154 | ;; |
| 155 | status) |
| 156 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 157 | echo "$n instance of onos running" |
| 158 | ;; |
| 159 | *) |
| 160 | echo "Usage: $0 {start|stop|restart|status|startifdown}" |
| 161 | exit 1 |
| 162 | esac |