Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Set paths |
| 4 | FL_HOME=`dirname $0` |
| 5 | FL_JAR="${FL_HOME}/target/floodlight.jar" |
| 6 | FL_LOGBACK="${FL_HOME}/logback.xml" |
| 7 | LOGDIR=${FL_HOME}/onos-logs |
| 8 | FL_LOG="${LOGDIR}/onos.`hostname`.log" |
| 9 | PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap" |
| 10 | LOGS="$FL_LOG $PCAP_LOG" |
| 11 | |
| 12 | # Set JVM options |
| 13 | JVM_OPTS="" |
| 14 | #JVM_OPTS="$JVM_OPTS -server -d64" |
| 15 | #JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m" |
| 16 | #JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods" |
| 17 | #JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192" |
| 18 | #JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8" |
| 19 | #JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false" |
| 20 | |
| 21 | # Set classpath to include titan libs |
| 22 | CLASSPATH=`echo ${FL_HOME}/lib/*.jar ${FL_HOME}/lib/titan/*.jar | sed 's/ /:/g'` |
| 23 | |
| 24 | # Create a logback file if required |
| 25 | cat <<EOF_LOGBACK >${FL_LOGBACK} |
| 26 | <configuration scan="true" debug="true"> |
| 27 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| 28 | <encoder> |
| 29 | <pattern>%level [%logger:%thread] %msg%n</pattern> |
| 30 | </encoder> |
| 31 | </appender> |
| 32 | |
| 33 | <appender name="FILE" class="ch.qos.logback.core.FileAppender"> |
| 34 | <file>${FL_LOG}</file> |
| 35 | <encoder> |
| 36 | <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> |
| 37 | </encoder> |
| 38 | </appender> |
| 39 | |
| 40 | <logger name="org" level="WARN"/> |
| 41 | <logger name="LogService" level="WARN"/> <!-- Restlet access logging --> |
| 42 | <logger name="net.floodlightcontroller.logging" level="WARN"/> |
| 43 | <logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/> |
| 44 | |
| 45 | <root level="DEBUG"> |
| 46 | <appender-ref ref="FILE" /> |
| 47 | </root> |
| 48 | </configuration> |
| 49 | EOF_LOGBACK |
| 50 | |
| 51 | #<appender-ref ref="STDOUT" /> |
| 52 | |
| 53 | function lotate { |
| 54 | logfile=$1 |
| 55 | nr_max=$2 |
| 56 | if [ -f $logfile ]; then |
| 57 | for i in `seq $(expr 10 - 1) -1 1`; do |
| 58 | if [ -f ${logfile}.${i} ]; then |
| 59 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 60 | fi |
| 61 | done |
| 62 | mv $logfile $logfile.1 |
| 63 | fi |
| 64 | } |
| 65 | |
| 66 | function start { |
| 67 | if [ ! -d ${LOGDIR} ]; then |
| 68 | mkdir -p ${LOGDIR} |
| 69 | fi |
| 70 | # Backup log files |
| 71 | for log in ${LOGS}; do |
| 72 | echo "rotate log: $log" |
| 73 | if [ -f ${log} ]; then |
| 74 | lotate ${log} |
| 75 | fi |
| 76 | done |
| 77 | |
| 78 | # Run floodlight |
| 79 | echo "Starting ONOS controller ..." |
| 80 | echo |
| 81 | java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -Xbootclasspath/a:$CLASSPATH -jar ${FL_JAR} -cf ./onos.properties > /dev/null 2>&1 & |
| 82 | sudo tcpdump -n -i eth0 'tcp port 6633' -s0 -w ${PCAP_LOG} & |
| 83 | } |
| 84 | |
| 85 | function stop { |
| 86 | # Kill the existing processes |
| 87 | flpid=`ps -edalf |grep java |grep logback.xml | awk '{print $4}'` |
| 88 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 89 | pids="$flpid $tdpid" |
| 90 | for p in ${pids}; do |
| 91 | if [ x$p != "x" ]; then |
| 92 | sudo kill -KILL $p |
| 93 | echo "Killed existing prosess (pid: $p)" |
| 94 | fi |
| 95 | done |
| 96 | } |
| 97 | |
| 98 | case "$1" in |
| 99 | start) |
| 100 | stop |
| 101 | start |
| 102 | ;; |
| 103 | stop) |
| 104 | stop |
| 105 | ;; |
| 106 | status) |
| 107 | n=`ps -edalf |grep java |grep logback.xml | wc -l` |
| 108 | echo "$n instance of onos running" |
| 109 | ;; |
| 110 | *) |
| 111 | echo "Usage: $0 {start|stop|restart|status}" |
| 112 | exit 1 |
| 113 | esac |