blob: e664d0964486e7c01d1693e3f9f2521ac01947a3 [file] [log] [blame]
#!/bin/bash
ulimit -c unlimited
# Set paths
ONOS_HOME="${ONOS_HOME:-`dirname $0`}"
RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud}
RAMCLOUD_BRANCH=${RAMCLOUD_BRANCH:-master}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${ONOS_HOME}/lib:${RAMCLOUD_HOME}/obj.${RAMCLOUD_BRANCH}
## Because the script change dir to $ONOS_HOME, we can set ONOS_LOGBACK and LOGDIR relative to $ONOS_HOME
ONOS_LOGBACK=${ONOS_LOGBACK:-${ONOS_HOME}/logback.`hostname`.xml}
LOGDIR=${ONOS_LOGDIR:-${ONOS_HOME}/onos-logs}
LOGBASE=${ONOS_LOGBASE:-onos.`hostname`}
ONOS_LOG="${LOGDIR}/${LOGBASE}.log"
PCAP_LOG="${LOGDIR}/${LOGBASE}.pcap"
LOGS="$ONOS_LOG $PCAP_LOG"
ONOS_PROPS=${ONOS_PROPS:-${ONOS_HOME}/conf/onos.properties}
JMX_PORT=${JMX_PORT:-7189}
# Set JVM options
JVM_OPTS="${JVM_OPTS:-}"
## If you want JaCoCo Code Coverage reports... uncomment line below
#JVM_OPTS="$JVM_OPTS -javaagent:${ONOS_HOME}/lib/jacocoagent.jar=dumponexit=true,output=file,destfile=${LOGDIR}/jacoco.exec"
JVM_OPTS="$JVM_OPTS -server -d64"
#JVM_OPTS="$JVM_OPTS -XX:+TieredCompilation -XX:InitialCodeCacheSize=512m -XX:ReservedCodeCacheSize=512m"
JVM_OPTS="$JVM_OPTS -Xmx4g -Xms4g -Xmn800m"
#JVM_OPTS="$JVM_OPTS -Xmx2g -Xms2g -Xmn800m"
#JVM_OPTS="$JVM_OPTS -Xmx1g -Xms1g -Xmn800m"
#JVM_OPTS="$JVM_OPTS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
JVM_OPTS="$JVM_OPTS -XX:+UseConcMarkSweepGC -XX:+UseAdaptiveSizePolicy -XX:+AggressiveOpts -XX:+UseFastAccessorMethods"
JVM_OPTS="$JVM_OPTS -XX:MaxInlineSize=8192 -XX:FreqInlineSize=8192"
JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8"
JVM_OPTS="$JVM_OPTS -XX:OnError=crash-logger" ;# For dumping core
#JVM_OPTS="$JVM_OPTS -Dpython.security.respectJavaAccessibility=false"
JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8 \
-XX:+UseThreadPriorities \
-XX:ThreadPriorityPolicy=42 \
-XX:+UseCompressedOops \
-Dcom.sun.management.jmxremote.port=$JMX_PORT \
-Dcom.sun.management.jmxremote.ssl=false \
-Dbenchmark.measureBP=0 \
-Dbenchmark.measureRc=0 \
-Dbenchmark.measureONOS=0 \
-Dcom.sun.management.jmxremote.authenticate=false"
JVM_OPTS="$JVM_OPTS -Dhazelcast.logging.type=slf4j"
# Set ONOS core main class
MAIN_CLASS="net.onrc.onos.ofcontroller.core.Main"
MVN=${MVN:-mvn -o}
CPFILE=${ONOS_HOME}/.javacp.`hostname`
if [ ! -f ${CPFILE} ]; then
${MVN} -f ${ONOS_HOME}/pom.xml compile
fi
JAVA_CP=`cat ${CPFILE}`
JAVA_CP="${JAVA_CP}:${ONOS_HOME}/target/classes"
#<logger name="net.floodlightcontroller.linkdiscovery.internal" level="TRACE"/>
#<appender-ref ref="STDOUT" />
function lotate {
logfile=$1
nr_max=${2:-10}
if [ -f $logfile ]; then
for i in `seq $(expr $nr_max - 1) -1 1`; do
if [ -f ${logfile}.${i} ]; then
mv -f ${logfile}.${i} ${logfile}.`expr $i + 1`
fi
done
mv $logfile $logfile.1
fi
}
function start {
if [ ! -d ${LOGDIR} ]; then
mkdir -p ${LOGDIR}
fi
# Backup log files
for log in ${LOGS}; do
echo "rotate log: $log"
if [ -f ${log} ]; then
lotate ${log}
fi
done
# Create a logback file if required
if [ ! -f ${ONOS_LOGBACK} ]; then
cat <<EOF_LOGBACK >${ONOS_LOGBACK}
<configuration scan="true" scanPeriod="1 minutes" debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%level [%logger:%thread] %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${ONOS_LOG}</file>
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
<immediateFlush>true</immediateFlush>
</encoder>
</appender>
<logger name="org" level="WARN"/>
<logger name="LogService" level="WARN"/> <!-- Restlet access logging -->
<logger name="net.floodlightcontroller.logging" level="WARN"/>
<logger name="com.thinkaurelius.titan" level="INFO"/>
<root level="DEBUG">
<appender-ref ref="FILE" />
</root>
</configuration>
EOF_LOGBACK
fi
# Run ONOS
echo "Starting ONOS controller ..."
echo
# XXX : MVN has to run at the project top dir
echo $ONOS_HOME
cd ${ONOS_HOME}
pwd
java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp ${JAVA_CP} ${MAIN_CLASS} -cf ${ONOS_PROPS} > ${LOGDIR}/${LOGBASE}.stdout 2>${LOGDIR}/${LOGBASE}.stderr &
echo "Waiting for ONOS to start..."
COUNT=0
ESTATE=0
while [ "$COUNT" != "10" ]; do
echo -n "."
sleep 1
# COUNT=$((COUNT + 1))
# sleep $COUNT
n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
if [ "$n" -ge "1" ]; then
echo ""
exit 0
fi
done
echo "Timed out"
exit 1
# echo "java ${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -jar ${ONOS_JAR} -cf ./onos.properties > /dev/null 2>&1 &"
# sudo -b /usr/sbin/tcpdump -n -i eth0 -s0 -w ${PCAP_LOG} 'tcp port 6633' > /dev/null 2>&1
}
function stop {
# Kill the existing processes
flpid=`jps -l |grep ${MAIN_CLASS} | awk '{print $1}'`
tdpid=`ps -edalf |grep tcpdump |grep ${PCAP_LOG} | awk '{print $4}'`
pids="$flpid $tdpid"
for p in ${pids}; do
if [ x$p != "x" ]; then
kill -TERM $p
echo "Killed existing process (pid: $p)"
fi
done
}
function check_db {
if [ -d "/tmp/cassandra.titan" ]; then
echo "Cassandra is running on local berkely db. Exitting"
exit
fi
n=`ps -edalf |grep java |grep apache-cassandra | wc -l`
if [ x$n == "x0" ]; then
echo "Cassandra is not running. Exitting"
exit
fi
}
case "$1" in
start)
stop
# check_db
start
;;
startnokill)
# check_db
start
;;
startifdown)
n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
if [ $n == 0 ]; then
start
else
echo "$n instance of onos running"
fi
;;
stop)
stop
;;
status)
n=`jps -l |grep "${MAIN_CLASS}" | wc -l`
echo "$n instance of onos running"
;;
*)
echo "Usage: $0 {start|stop|status|startifdown}"
exit 1
esac