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"/> |
Jonathan Hart | 64a036d | 2014-01-15 10:58:01 -0800 | [diff] [blame] | 100 | <logger name="com.thinkaurelius.titan" level="INFO"/> |
mininet | 4a828f2 | 2013-12-10 14:22:39 -0800 | [diff] [blame] | 101 | |
| 102 | <root level="DEBUG"> |
| 103 | <appender-ref ref="FILE" /> |
| 104 | </root> |
| 105 | </configuration> |
| 106 | EOF_LOGBACK |
| 107 | fi |
| 108 | |
Yuta HIGUCHI | 4fb214c | 2013-12-10 14:56:52 -0800 | [diff] [blame] | 109 | # Run ONOS |
mininet | 4a828f2 | 2013-12-10 14:22:39 -0800 | [diff] [blame] | 110 | echo "Starting ONOS controller ..." |
| 111 | echo |
| 112 | |
| 113 | # XXX : MVN has to run at the project top dir |
| 114 | echo $ONOS_HOME |
| 115 | cd ${ONOS_HOME} |
Yuta HIGUCHI | 8d9723d | 2013-12-21 00:10:07 -0800 | [diff] [blame] | 116 | 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] | 117 | |
| 118 | echo "Waiting for ONOS to start..." |
| 119 | COUNT=0 |
| 120 | ESTATE=0 |
| 121 | while [ "$COUNT" != "10" ]; do |
| 122 | echo -n "." |
| 123 | sleep 1 |
| 124 | # COUNT=$((COUNT + 1)) |
| 125 | # sleep $COUNT |
| 126 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 127 | if [ "$n" -ge "1" ]; then |
| 128 | echo "" |
| 129 | exit 0 |
| 130 | fi |
| 131 | done |
| 132 | echo "Timed out" |
| 133 | exit 1 |
| 134 | |
| 135 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
| 136 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
| 137 | } |
| 138 | |
| 139 | function stop { |
| 140 | # Kill the existing processes |
| 141 | flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'` |
| 142 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 143 | pids="$flpid $tdpid" |
| 144 | for p in ${pids}; do |
| 145 | if [ x$p != "x" ]; then |
| 146 | kill -TERM $p |
| 147 | echo "Killed existing process (pid: $p)" |
| 148 | fi |
| 149 | done |
| 150 | } |
| 151 | |
| 152 | function check_db { |
| 153 | if [ -d "/tmp/cassandra.titan" ]; then |
| 154 | echo "Cassandra is running on local berkely db. Exitting" |
| 155 | exit |
| 156 | fi |
| 157 | n=`ps -edalf |grep java |grep apache-cassandra | wc -l` |
| 158 | if [ x$n == "x0" ]; then |
| 159 | echo "Cassandra is not running. Exitting" |
| 160 | exit |
| 161 | fi |
| 162 | } |
| 163 | |
| 164 | case "$1" in |
| 165 | start) |
| 166 | stop |
| 167 | check_db |
| 168 | start |
| 169 | ;; |
| 170 | startifdown) |
| 171 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 172 | if [ $n == 0 ]; then |
| 173 | start |
| 174 | else |
| 175 | echo "$n instance of onos running" |
| 176 | fi |
| 177 | ;; |
| 178 | stop) |
| 179 | stop |
| 180 | ;; |
| 181 | status) |
| 182 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 183 | echo "$n instance of onos running" |
| 184 | ;; |
| 185 | *) |
Yuta HIGUCHI | 645a668 | 2014-01-02 11:10:12 -0800 | [diff] [blame] | 186 | echo "Usage: $0 {start|stop|status|startifdown}" |
mininet | 4a828f2 | 2013-12-10 14:22:39 -0800 | [diff] [blame] | 187 | exit 1 |
| 188 | esac |