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" |
Jonathan Hart | e4997b9 | 2013-03-22 09:57:41 -0700 | [diff] [blame] | 6 | FL_ONLY_JAR="${FL_HOME}/target/floodlight-only.jar" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 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 | #JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false" |
| 21 | |
| 22 | # Set classpath to include titan libs |
Jonathan Hart | e4997b9 | 2013-03-22 09:57:41 -0700 | [diff] [blame] | 23 | #CLASSPATH=`echo ${FL_HOME}/lib/*.jar ${FL_HOME}/lib/titan/*.jar | sed 's/ /:/g'` |
| 24 | CLASSPATH="${FL_ONLY_JAR}:${FL_HOME}/lib/*:${FL_HOME}/lib/titan/*" |
| 25 | MAIN_CLASS="net.floodlightcontroller.core.Main" |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 26 | |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 27 | #<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/> |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 28 | #<appender-ref ref="STDOUT" /> |
| 29 | |
| 30 | function lotate { |
Masayoshi Kobayashi | 274c07d | 2013-02-20 21:38:16 +0000 | [diff] [blame] | 31 | logfile=$1 |
| 32 | nr_max=${2:-10} |
| 33 | if [ -f $logfile ]; then |
| 34 | for i in `seq $(expr $nr_max - 1) -1 1`; do |
| 35 | if [ -f ${logfile}.${i} ]; then |
| 36 | mv -f ${logfile}.${i} ${logfile}.`expr $i + 1` |
| 37 | fi |
| 38 | done |
| 39 | mv $logfile $logfile.1 |
| 40 | fi |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | function start { |
| 44 | if [ ! -d ${LOGDIR} ]; then |
| 45 | mkdir -p ${LOGDIR} |
| 46 | fi |
| 47 | # Backup log files |
| 48 | for log in ${LOGS}; do |
| 49 | echo "rotate log: $log" |
| 50 | if [ -f ${log} ]; then |
| 51 | lotate ${log} |
| 52 | fi |
| 53 | done |
| 54 | |
Jonathan Hart | 0ae2777 | 2013-03-19 13:03:52 -0700 | [diff] [blame] | 55 | # Create a logback file if required |
| 56 | cat <<EOF_LOGBACK >${FL_LOGBACK} |
| 57 | <configuration scan="true" debug="true"> |
| 58 | <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
| 59 | <encoder> |
| 60 | <pattern>%level [%logger:%thread] %msg%n</pattern> |
| 61 | </encoder> |
| 62 | </appender> |
| 63 | |
| 64 | <appender name="FILE" class="ch.qos.logback.core.FileAppender"> |
| 65 | <file>${FL_LOG}</file> |
| 66 | <encoder> |
| 67 | <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> |
| 68 | </encoder> |
| 69 | </appender> |
| 70 | |
| 71 | <logger name="org" level="WARN"/> |
| 72 | <logger name="LogService" level="WARN"/> <!-- Restlet access logging --> |
| 73 | <logger name="net.floodlightcontroller.logging" level="WARN"/> |
| 74 | |
| 75 | <root level="DEBUG"> |
| 76 | <appender-ref ref="FILE" /> |
| 77 | </root> |
| 78 | </configuration> |
| 79 | EOF_LOGBACK |
| 80 | |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 81 | # Run floodlight |
| 82 | echo "Starting ONOS controller ..." |
| 83 | echo |
Jonathan Hart | e4997b9 | 2013-03-22 09:57:41 -0700 | [diff] [blame] | 84 | #java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ${FL_HOME}/onos.properties > /dev/null 2>&1 & |
| 85 | java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -cp ${CLASSPATH} ${MAIN_CLASS} -cf ${FL_HOME}/onos.properties > /dev/null 2>&1 & |
| 86 | |
| 87 | |
Ubuntu | aea2a68 | 2013-02-08 08:30:10 +0000 | [diff] [blame] | 88 | # echo "java ${JVM_OPTS} -Dlogback.configurationFile=${FL_LOGBACK} -jar ${FL_JAR} -cf ./onos.properties > /dev/null 2>&1 &" |
Masayoshi Kobayashi | 8849a66 | 2013-03-14 22:18:51 +0000 | [diff] [blame] | 89 | # 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] | 90 | } |
| 91 | |
| 92 | function stop { |
| 93 | # Kill the existing processes |
| 94 | flpid=`ps -edalf |grep java |grep logback.xml | awk '{print $4}'` |
| 95 | tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'` |
| 96 | pids="$flpid $tdpid" |
| 97 | for p in ${pids}; do |
| 98 | if [ x$p != "x" ]; then |
Pavlin Radoslavov | b531d71 | 2013-03-29 15:13:43 -0700 | [diff] [blame] | 99 | kill -KILL $p |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 100 | echo "Killed existing prosess (pid: $p)" |
| 101 | fi |
| 102 | done |
| 103 | } |
| 104 | |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 105 | function deldb { |
| 106 | # Delete the berkeley db database |
| 107 | if [ -d "/tmp/cassandra.titan" ]; then |
| 108 | rm -rf /tmp/cassandra.titan |
| 109 | mkdir /tmp/cassandra.titan |
| 110 | fi |
| 111 | } |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 112 | function check_db { |
| 113 | if [ -d "/tmp/cassandra.titan" ]; then |
| 114 | echo "Cassandra is running on local berkely db. Exitting" |
| 115 | exit |
| 116 | fi |
| 117 | n=`ps -edalf |grep java |grep apache-cassandra | wc -l` |
Masayoshi Kobayashi | e772c7c | 2013-02-28 00:36:33 +0000 | [diff] [blame] | 118 | if [ x$n == "x0" ]; then |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 119 | echo "Cassandra is not running. Exitting" |
| 120 | exit |
| 121 | fi |
| 122 | } |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 123 | |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 124 | case "$1" in |
| 125 | start) |
| 126 | stop |
Masayoshi Kobayashi | cbd5e0a | 2013-02-25 19:00:19 +0000 | [diff] [blame] | 127 | check_db |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 128 | start |
| 129 | ;; |
| 130 | stop) |
| 131 | stop |
| 132 | ;; |
admin | 6bdc999 | 2013-02-06 11:06:02 -0800 | [diff] [blame] | 133 | deldb) |
| 134 | deldb |
| 135 | ;; |
Ubuntu | 08edc7a | 2013-01-30 17:59:19 +0000 | [diff] [blame] | 136 | status) |
| 137 | n=`ps -edalf |grep java |grep logback.xml | wc -l` |
| 138 | echo "$n instance of onos running" |
| 139 | ;; |
| 140 | *) |
| 141 | echo "Usage: $0 {start|stop|restart|status}" |
| 142 | exit 1 |
| 143 | esac |