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 | |
Yuta HIGUCHI | 8d9723d | 2013-12-21 00:10:07 -0800 | [diff] [blame] | 46 | if [ ! -f ${ONOS_HOME}/.javacp ]; then |
| 47 | ${MVN} -f ${ONOS_HOME}/pom.xml compile |
| 48 | fi |
| 49 | JAVA_CP=`cat ${ONOS_HOME}/.javacp` |
| 50 | JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes" |
| 51 | |
mininet | 4a828f2 | 2013-12-10 14:22:39 -0800 | [diff] [blame] | 52 | #<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/> |
| 53 | #<appender-ref ref="STDOUT" /> |
| 54 | |
| 55 | function lotate { |
| 56 | logfile=$1 |
| 57 | nr_max=${2:-10} |
| 58 | if [ -f $logfile ]; then |
| 59 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 60 | if [ -f ${logfile}.${i} ]; then |
| 61 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 62 | fi |
| 63 | done |
| 64 | mv $logfile $logfile.1 |
| 65 | fi |
| 66 | } |
| 67 | |
| 68 | function start { |
| 69 | if [ ! -d ${LOGDIR} ]; then |
| 70 | mkdir -p ${LOGDIR} |
| 71 | fi |
| 72 | # Backup log files |
| 73 | for log in ${LOGS}; do |
| 74 | echo "rotate log: $log" |
| 75 | if [ -f ${log} ]; then |
| 76 | lotate ${log} |
| 77 | fi |
| 78 | done |
| 79 | |
| 80 | # Create a logback file if required |
| 81 | if [ ! -f ${ONOS_LOGBACK} ]; then |
| 82 | cat <<EOF_LOGBACK >${ONOS_LOGBACK} |
| 83 | <configuration scan="true" debug="true"> |
| 84 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| 85 | <encoder> |
| 86 | <pattern>%level [%logger:%thread] %msg%n</pattern> |
| 87 | </encoder> |
| 88 | </appender> |
| 89 | |
| 90 | <appender name="FILE" class="ch.qos.logback.core.FileAppender"> |
| 91 | <file>${ONOS_LOG}</file> |
| 92 | <encoder> |
| 93 | <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> |
| 94 | </encoder> |
| 95 | </appender> |
| 96 | |
| 97 | <logger name="org" level="WARN"/> |
| 98 | <logger name="LogService" level="WARN"/> <!-- Restlet access logging --> |
| 99 | <logger name="net.floodlightcontroller.logging" level="WARN"/> |
| 100 | |
| 101 | <root level="DEBUG"> |
| 102 | <appender-ref ref="FILE" /> |
| 103 | </root> |
| 104 | </configuration> |
| 105 | EOF_LOGBACK |
| 106 | fi |
| 107 | |
Yuta HIGUCHI | 4fb214c | 2013-12-10 14:56:52 -0800 | [diff] [blame] | 108 | # Run ONOS |
mininet | 4a828f2 | 2013-12-10 14:22:39 -0800 | [diff] [blame] | 109 | echo "Starting ONOS controller ..." |
| 110 | echo |
| 111 | |
| 112 | # XXX : MVN has to run at the project top dir |
| 113 | echo $ONOS_HOME |
| 114 | cd ${ONOS_HOME} |
Yuta HIGUCHI | 8d9723d | 2013-12-21 00:10:07 -0800 | [diff] [blame] | 115 | java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ./conf/onos.properties > ${LOGDIR}/onos.`hostname`.stdout 2>${LOGDIR}/onos.`hostname`.stderr & |
mininet | 4a828f2 | 2013-12-10 14:22:39 -0800 | [diff] [blame] | 116 | |
| 117 | echo "Waiting for ONOS to start..." |
| 118 | COUNT=0 |
| 119 | ESTATE=0 |
| 120 | while [ "$COUNT" != "10" ]; do |
| 121 | echo -n "." |
| 122 | sleep 1 |
| 123 | # COUNT=$((COUNT + 1)) |
| 124 | # sleep $COUNT |
| 125 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 126 | if [ "$n" -ge "1" ]; then |
| 127 | echo "" |
| 128 | exit 0 |
| 129 | fi |
| 130 | done |
| 131 | echo "Timed out" |
| 132 | exit 1 |
| 133 | |
| 134 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
| 135 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
| 136 | } |
| 137 | |
| 138 | function stop { |
| 139 | # Kill the existing processes |
| 140 | flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'` |
| 141 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 142 | pids="$flpid $tdpid" |
| 143 | for p in ${pids}; do |
| 144 | if [ x$p != "x" ]; then |
| 145 | kill -TERM $p |
| 146 | echo "Killed existing process (pid: $p)" |
| 147 | fi |
| 148 | done |
| 149 | } |
| 150 | |
| 151 | function check_db { |
| 152 | if [ -d "/tmp/cassandra.titan" ]; then |
| 153 | echo "Cassandra is running on local berkely db. Exitting" |
| 154 | exit |
| 155 | fi |
| 156 | n=`ps -edalf |grep java |grep apache-cassandra | wc -l` |
| 157 | if [ x$n == "x0" ]; then |
| 158 | echo "Cassandra is not running. Exitting" |
| 159 | exit |
| 160 | fi |
| 161 | } |
| 162 | |
| 163 | case "$1" in |
| 164 | start) |
| 165 | stop |
| 166 | check_db |
| 167 | start |
| 168 | ;; |
| 169 | startifdown) |
| 170 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 171 | if [ $n == 0 ]; then |
| 172 | start |
| 173 | else |
| 174 | echo "$n instance of onos running" |
| 175 | fi |
| 176 | ;; |
| 177 | stop) |
| 178 | stop |
| 179 | ;; |
| 180 | status) |
| 181 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 182 | echo "$n instance of onos running" |
| 183 | ;; |
| 184 | *) |
| 185 | echo "Usage: $0 {start|stop|restart|status|startifdown}" |
| 186 | exit 1 |
| 187 | esac |