Pankaj Berde | 1b399bb | 2013-06-12 11:04:11 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Set paths |
| 4 | FL_HOME=`dirname $0` |
| 5 | FL_JAR="${FL_HOME}/target/floodlight.jar" |
| 6 | FL_ONLY_JAR="${FL_HOME}/target/floodlight-only.jar" |
| 7 | FL_LOGBACK="${FL_HOME}/logback.xml" |
| 8 | LOGDIR=${FL_HOME}/onos-logs |
| 9 | FL_LOG="${LOGDIR}/onos.`hostname`.log" |
| 10 | PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap" |
| 11 | LOGS="$FL_LOG $PCAP_LOG" |
| 12 | |
| 13 | # Set JVM options |
| 14 | JVM_OPTS="" |
| 15 | JVM_OPTS="$JVM_OPTS -server -d64" |
| 16 | JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m" |
| 17 | JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
| 18 | JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192" |
| 19 | JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \ |
| 20 | -Dcom.sun.management.jmxremote.port=7199 \ |
| 21 | -Dcom.sun.management.jmxremote.ssl=false \ |
| 22 | -Dcom.sun.management.jmxremote.authenticate=false" |
| 23 | |
| 24 | #JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false" |
| 25 | |
| 26 | # Set classpath to include titan libs |
| 27 | #CLASSPATH=`echo ${FL_HOME}/lib/*.jar ${FL_HOME}/lib/titan/*.jar | sed 's/ /:/g'` |
| 28 | CLASSPATH="${FL_ONLY_JAR}:${FL_HOME}/lib/*:${FL_HOME}/lib/titan/*" |
| 29 | MAIN_CLASS="net.floodlightcontroller.core.Main" |
| 30 | |
| 31 | #<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/> |
| 32 | #<appender-ref ref="STDOUT" /> |
| 33 | |
| 34 | function lotate { |
| 35 | logfile=$1 |
| 36 | nr_max=${2:-10} |
| 37 | if [ -f $logfile ]; then |
| 38 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 39 | if [ -f ${logfile}.${i} ]; then |
| 40 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 41 | fi |
| 42 | done |
| 43 | mv $logfile $logfile.1 |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | function start { |
| 48 | if [ ! -d ${LOGDIR} ]; then |
| 49 | mkdir -p ${LOGDIR} |
| 50 | fi |
| 51 | # Backup log files |
| 52 | for log in ${LOGS}; do |
| 53 | echo "rotate log: $log" |
| 54 | if [ -f ${log} ]; then |
| 55 | lotate ${log} |
| 56 | fi |
| 57 | done |
| 58 | |
| 59 | # Create a logback file if required |
| 60 | cat <<EOF_LOGBACK >${FL_LOGBACK} |
| 61 | <configuration scan="true" debug="true"> |
| 62 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| 63 | <encoder> |
| 64 | <pattern>%level [%logger:%thread] %msg%n</pattern> |
| 65 | </encoder> |
| 66 | </appender> |
| 67 | |
| 68 | <appender name="FILE" class="ch.qos.logback.core.FileAppender"> |
| 69 | <file>${FL_LOG}</file> |
| 70 | <encoder> |
| 71 | <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> |
| 72 | </encoder> |
| 73 | </appender> |
| 74 | |
| 75 | <logger name="org" level="WARN"/> |
| 76 | <logger name="LogService" level="WARN"/> <!-- Restlet access logging --> |
| 77 | <logger name="net.floodlightcontroller.logging" level="WARN"/> |
| 78 | |
| 79 | <root level="DEBUG"> |
| 80 | <appender-ref ref="FILE" /> |
| 81 | </root> |
| 82 | </configuration> |
| 83 | EOF_LOGBACK |
| 84 | |
| 85 | # Run floodlight |
| 86 | echo "Starting ONOS controller ..." |
| 87 | echo |
| 88 | #java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ${FL_HOME}/onos.properties > /dev/null 2>&1 & |
| 89 | #java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -cp ${CLASSPATH} ${MAIN_CLASS} -cf ${FL_HOME}/onos.properties > /dev/n |
| 90 | |
| 91 | mvn exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${FL_HOME}/conf/onos-embedded.properties" > ${LOGDIR}/onos.stdout 2>${LOGDIR}/onos.stderr & |
| 92 | |
| 93 | echo "Waiting for ONOS to start..." |
| 94 | COUNT=0 |
| 95 | ESTATE=0 |
| 96 | while [ "$COUNT" != "10" ]; do |
| 97 | COUNT=$((COUNT + 1)) |
| 98 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 99 | if [ "$n" -ge "1" ]; then |
| 100 | exit 0 |
| 101 | fi |
| 102 | sleep $COUNT |
| 103 | done |
| 104 | echo "Timed out" |
| 105 | exit 1 |
| 106 | |
| 107 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
| 108 | # sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
| 109 | } |
| 110 | |
| 111 | function stop { |
| 112 | # Kill the existing processes |
| 113 | flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'` |
| 114 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 115 | pids="$flpid $tdpid" |
| 116 | for p in ${pids}; do |
| 117 | if [ x$p != "x" ]; then |
| 118 | kill -KILL $p |
| 119 | echo "Killed existing prosess (pid: $p)" |
| 120 | fi |
| 121 | done |
| 122 | } |
| 123 | |
| 124 | function deldb { |
| 125 | # Delete the cassandra data |
| 126 | if [ -d "/tmp/cassandra" ]; then |
| 127 | rm -rf /tmp/cassandra/* |
| 128 | fi |
| 129 | } |
| 130 | |
| 131 | case "$1" in |
| 132 | start) |
| 133 | stop |
| 134 | start |
| 135 | ;; |
| 136 | startifdown) |
| 137 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 138 | if [ $n == 0 ]; then |
| 139 | start |
| 140 | else |
| 141 | echo "$n instance of onos running" |
| 142 | fi |
| 143 | ;; |
| 144 | stop) |
| 145 | stop |
| 146 | ;; |
| 147 | deldb) |
| 148 | deldb |
| 149 | ;; |
| 150 | status) |
| 151 | n=`jps -l |grep "${MAIN_CLASS}" | wc -l` |
| 152 | echo "$n instance of onos running" |
| 153 | ;; |
| 154 | *) |
| 155 | echo "Usage: $0 {start|stop|restart|status|startifdown}" |
| 156 | exit 1 |
| 157 | esac |