mininet | 4a828f2 | 2013-12-10 14:22:39 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Set paths |
| 4 | if [ -z "${ONOS_HOME}" ]; then |
| 5 | ONOS_HOME=`dirname $0` |
| 6 | fi |
| 7 | |
| 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 |
| 13 | ONOS_LOG="${LOGDIR}/onos.`hostname`.log" |
| 14 | PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap" |
| 15 | LOGS="$ONOS_LOG $PCAP_LOG" |
| 16 | |
| 17 | # Set JVM options |
| 18 | JVM_OPTS="" |
| 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" |
| 21 | JVM_OPTS="$JVM_OPTS -server -d64" |
| 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" |
| 25 | JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
| 26 | JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192" |
| 27 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8" |
| 28 | JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core |
| 29 | #JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false" |
| 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" |
| 37 | JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j" |
| 38 | |
| 39 | # Set ONOS core main class |
| 40 | MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main" |
| 41 | |
| 42 | if [ -z "${MVN}" ]; then |
| 43 | MVN="mvn -o" |
| 44 | fi |
| 45 | |
| 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 |
| 75 | if [ ! -f ${ONOS_LOGBACK} ]; then |
| 76 | cat <<EOF_LOGBACK >${ONOS_LOGBACK} |
| 77 | <configuration scan="true" debug="true"> |
| 78 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| 79 | <encoder> |
| 80 | <pattern>%level [%logger:%thread] %msg%n</pattern> |
| 81 | </encoder> |
| 82 | </appender> |
| 83 | |
| 84 | <appender name="FILE" class="ch.qos.logback.core.FileAppender"> |
| 85 | <file>${ONOS_LOG}</file> |
| 86 | <encoder> |
| 87 | <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> |
| 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 | fi |
| 101 | |
Yuta HIGUCHI | 4fb214c | 2013-12-10 14:56:52 -0800 | [diff] [blame] | 102 | # Run ONOS |
mininet | 4a828f2 | 2013-12-10 14:22:39 -0800 | [diff] [blame] | 103 | echo "Starting ONOS controller ..." |
| 104 | echo |
| 105 | |
| 106 | # XXX : MVN has to run at the project top dir |
| 107 | echo $ONOS_HOME |
| 108 | cd ${ONOS_HOME} |
| 109 | pwd |
| 110 | echo "${MVN} exec:exec -Dexec.executable=\"java\" -Dexec.args=\"${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ./conf/onos.properties\"" |
| 111 | |
| 112 | ${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 & |
| 113 | |
| 114 | echo "Waiting for ONOS to start..." |
| 115 | COUNT=0 |
| 116 | ESTATE=0 |
| 117 | while [ "$COUNT" != "10" ]; do |
| 118 | echo -n "." |
| 119 | sleep 1 |
| 120 | # COUNT=$((COUNT + 1)) |
| 121 | # sleep $COUNT |
| 122 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 123 | if [ "$n" -ge "1" ]; then |
| 124 | echo "" |
| 125 | exit 0 |
| 126 | fi |
| 127 | done |
| 128 | echo "Timed out" |
| 129 | exit 1 |
| 130 | |
| 131 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
| 132 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
| 133 | } |
| 134 | |
| 135 | function stop { |
| 136 | # Kill the existing processes |
| 137 | flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'` |
| 138 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 139 | pids="$flpid $tdpid" |
| 140 | for p in ${pids}; do |
| 141 | if [ x$p != "x" ]; then |
| 142 | kill -TERM $p |
| 143 | echo "Killed existing process (pid: $p)" |
| 144 | fi |
| 145 | done |
| 146 | } |
| 147 | |
| 148 | function check_db { |
| 149 | if [ -d "/tmp/cassandra.titan" ]; then |
| 150 | echo "Cassandra is running on local berkely db. Exitting" |
| 151 | exit |
| 152 | fi |
| 153 | n=`ps -edalf |grep java |grep apache-cassandra | wc -l` |
| 154 | if [ x$n == "x0" ]; then |
| 155 | echo "Cassandra is not running. Exitting" |
| 156 | exit |
| 157 | fi |
| 158 | } |
| 159 | |
| 160 | case "$1" in |
| 161 | start) |
| 162 | stop |
| 163 | check_db |
| 164 | start |
| 165 | ;; |
| 166 | startifdown) |
| 167 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 168 | if [ $n == 0 ]; then |
| 169 | start |
| 170 | else |
| 171 | echo "$n instance of onos running" |
| 172 | fi |
| 173 | ;; |
| 174 | stop) |
| 175 | stop |
| 176 | ;; |
| 177 | status) |
| 178 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 179 | echo "$n instance of onos running" |
| 180 | ;; |
| 181 | *) |
| 182 | echo "Usage: $0 {start|stop|restart|status|startifdown}" |
| 183 | exit 1 |
| 184 | esac |