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"/> |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 43 | |
| 44 | <root level="DEBUG"> |
| 45 | <appender-ref ref="FILE" /> |
| 46 | </root> |
| 47 | </configuration> |
| 48 | EOF_LOGBACK |
| 49 | |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 50 | #<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/> |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 51 | #<appender-ref ref="STDOUT" /> |
| 52 | |
| 53 | function lotate { |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 54 | logfile=$1 |
| 55 | nr_max=${2:-10} |
| 56 | if [ -f $logfile ]; then |
| 57 | for i in `seq $(expr $nr_max - 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 |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 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 |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 81 | java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ./onos.properties > /dev/null 2>&1 & |
Ubuntu | aea2a68 | 2013-02-08 08:30:10 +0000 | [diff] [blame] | 82 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
Ubuntu | 787c3ad | 2013-02-07 07:38:24 +0000 | [diff] [blame] | 83 | sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1 |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | function stop { |
| 87 | # Kill the existing processes |
| 88 | flpid=`ps -edalf |grep java |grep logback.xml | awk '{print $4}'` |
| 89 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 90 | pids="$flpid $tdpid" |
| 91 | for p in ${pids}; do |
| 92 | if [ x$p != "x" ]; then |
| 93 | sudo kill -KILL $p |
| 94 | echo "Killed existing prosess (pid: $p)" |
| 95 | fi |
| 96 | done |
| 97 | } |
| 98 | |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 99 | function deldb { |
| 100 | # Delete the berkeley db database |
| 101 | if [ -d "/tmp/cassandra.titan" ]; then |
| 102 | rm -rf /tmp/cassandra.titan |
| 103 | mkdir /tmp/cassandra.titan |
| 104 | fi |
| 105 | } |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 106 | function check_db { |
| 107 | if [ -d "/tmp/cassandra.titan" ]; then |
| 108 | echo "Cassandra is running on local berkely db. Exitting" |
| 109 | exit |
| 110 | fi |
| 111 | n=`ps -edalf |grep java |grep apache-cassandra | wc -l` |
| 112 | if [ x$n != "x1" ]; then |
| 113 | echo "Cassandra is not running. Exitting" |
| 114 | exit |
| 115 | fi |
| 116 | } |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 117 | |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 118 | case "$1" in |
| 119 | start) |
| 120 | stop |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 121 | check_db |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 122 | start |
| 123 | ;; |
| 124 | stop) |
| 125 | stop |
| 126 | ;; |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 127 | deldb) |
| 128 | deldb |
| 129 | ;; |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 130 | status) |
| 131 | n=`ps -edalf |grep java |grep logback.xml | wc -l` |
| 132 | echo "$n instance of onos running" |
| 133 | ;; |
| 134 | *) |
| 135 | echo "Usage: $0 {start|stop|restart|status}" |
| 136 | exit 1 |
| 137 | esac |