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 |
Naoki Shiota | 6e44b37 | 2013-10-14 14:33:58 -0700 | [diff] [blame] | 7 | ONOS_LOGBACK="${ONOS_HOME}/logback.`hostname`.xml" |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 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 \ |
Pavlin Radoslavov | 8709f48 | 2013-10-15 02:10:41 -0700 | [diff] [blame] | 23 | -XX:+UseCompressedOops \ |
Pankaj Berde | ff1fe03 | 2013-06-27 14:59:00 -0700 | [diff] [blame] | 24 | -Dcassandra.compaction.priority=1 \ |
Pavlin Radoslavov | 8709f48 | 2013-10-15 02:10:41 -0700 | [diff] [blame] | 25 | -Dcom.sun.management.jmxremote.port=7199 \ |
| 26 | -Dcom.sun.management.jmxremote.ssl=false \ |
| 27 | -Dcom.sun.management.jmxremote.authenticate=false" |
Pavlin Radoslavov | 579983b | 2013-10-15 08:58:24 -0700 | [diff] [blame] | 28 | JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 29 | |
| 30 | #JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false" |
| 31 | |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 32 | # Set Main class to start ONOS core |
HIGUCHI Yuta | 49cf4d2 | 2013-06-17 12:15:17 -0700 | [diff] [blame] | 33 | MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 34 | |
HIGUCHI Yuta | 88f3bf3 | 2013-06-20 10:37:47 -0700 | [diff] [blame] | 35 | if [ -z "${MVN}" ]; then |
| 36 | MVN="mvn" |
| 37 | fi |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 38 | #<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/> |
| 39 | #<appender-ref ref="STDOUT" /> |
| 40 | |
| 41 | function lotate { |
| 42 | logfile=$1 |
| 43 | nr_max=${2:-10} |
| 44 | if [ -f $logfile ]; then |
| 45 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 46 | if [ -f ${logfile}.${i} ]; then |
| 47 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 48 | fi |
| 49 | done |
| 50 | mv $logfile $logfile.1 |
| 51 | fi |
| 52 | } |
| 53 | |
| 54 | function start { |
| 55 | if [ ! -d ${LOGDIR} ]; then |
| 56 | mkdir -p ${LOGDIR} |
| 57 | fi |
| 58 | # Backup log files |
| 59 | for log in ${LOGS}; do |
| 60 | echo "rotate log: $log" |
| 61 | if [ -f ${log} ]; then |
| 62 | lotate ${log} |
| 63 | fi |
| 64 | done |
| 65 | |
| 66 | # Create a logback file if required |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 67 | cat <<EOF_LOGBACK >${ONOS_LOGBACK} |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 68 | <configuration scan="true" debug="true"> |
| 69 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| 70 | <encoder> |
| 71 | <pattern>%level [%logger:%thread] %msg%n</pattern> |
| 72 | </encoder> |
| 73 | </appender> |
| 74 | |
| 75 | <appender name="FILE" class="ch.qos.logback.core.FileAppender"> |
Masayoshi Kobayashi | 056cd47 | 2013-06-20 16:47:14 -0700 | [diff] [blame] | 76 | <file>${ONOS_LOG}</file> |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 77 | <encoder> |
| 78 | <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> |
| 79 | </encoder> |
| 80 | </appender> |
| 81 | |
| 82 | <logger name="org" level="WARN"/> |
| 83 | <logger name="LogService" level="WARN"/> <!-- Restlet access logging --> |
| 84 | <logger name="net.floodlightcontroller.logging" level="WARN"/> |
| 85 | |
| 86 | <root level="DEBUG"> |
| 87 | <appender-ref ref="FILE" /> |
| 88 | </root> |
| 89 | </configuration> |
| 90 | EOF_LOGBACK |
| 91 | |
| 92 | # Run floodlight |
| 93 | echo "Starting ONOS controller ..." |
| 94 | echo |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 95 | |
Masayoshi Kobayashi | 9d06fc5 | 2013-06-20 23:05:30 -0700 | [diff] [blame] | 96 | # XXX MVN has to run at the project top dir.. |
| 97 | cd ${ONOS_HOME} |
Naoki Shiota | 6e44b37 | 2013-10-14 14:33:58 -0700 | [diff] [blame] | 98 | echo "${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\"" |
Masayoshi Kobayashi | a8e3835 | 2013-06-20 16:52:40 -0700 | [diff] [blame] | 99 | ${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] | 100 | |
| 101 | echo "Waiting for ONOS to start..." |
| 102 | COUNT=0 |
| 103 | ESTATE=0 |
| 104 | while [ "$COUNT" != "10" ]; do |
| 105 | COUNT=$((COUNT + 1)) |
| 106 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 107 | if [ "$n" -ge "1" ]; then |
| 108 | exit 0 |
| 109 | fi |
| 110 | sleep $COUNT |
| 111 | done |
| 112 | echo "Timed out" |
| 113 | exit 1 |
| 114 | |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 115 | 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] | 116 | } |
| 117 | |
| 118 | function stop { |
| 119 | # Kill the existing processes |
| 120 | flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'` |
| 121 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 122 | pids="$flpid $tdpid" |
| 123 | for p in ${pids}; do |
| 124 | if [ x$p != "x" ]; then |
| 125 | kill -KILL $p |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 126 | echo "Killed existing process (pid: $p)" |
Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 127 | fi |
| 128 | done |
| 129 | } |
| 130 | |
| 131 | function deldb { |
| 132 | # Delete the cassandra data |
| 133 | if [ -d "/tmp/cassandra" ]; then |
| 134 | rm -rf /tmp/cassandra/* |
| 135 | fi |
| 136 | } |
| 137 | |
| 138 | case "$1" in |
| 139 | start) |
| 140 | stop |
| 141 | start |
| 142 | ;; |
| 143 | startifdown) |
| 144 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 145 | if [ $n == 0 ]; then |
| 146 | start |
| 147 | else |
| 148 | echo "$n instance of onos running" |
| 149 | fi |
| 150 | ;; |
| 151 | stop) |
| 152 | stop |
| 153 | ;; |
| 154 | deldb) |
| 155 | deldb |
| 156 | ;; |
| 157 | status) |
| 158 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 159 | echo "$n instance of onos running" |
| 160 | ;; |
| 161 | *) |
| 162 | echo "Usage: $0 {start|stop|restart|status|startifdown}" |
| 163 | exit 1 |
| 164 | esac |