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