#!/bin/bash # source variables if [ "$TMP" = "" ]; then TMP=/tmp fi PWD=`pwd` . "$PWD/env.sh" PARAM=$@ # make some checks JAVA_BINARY=$JAVA_HOME/bin/java if [[ ! -d "$JAVA_HOME" ]]; then echo "Could not find $JAVA_BINARY set in env.sh. Trying to find the correct one..." JAVA_VERSION=$(java -version 2>&1 | sed 's/java version "\(.*\)\.\(.*\)\..*"/\1\2/; 1q') if [ "$JAVA_VERSION" -lt 17 ]; then echo "The current Java version ($JAVA_VERSION) does not match the requirements (>= 1.7)." exit fi JAVA_BINARY=`which java` echo "Using Java from $JAVA_BINARY" fi # disable AWT requiring X11 and the correct DISPLAY variable setting; failing to do so # can result in trouble generating QR codes in the back-end ADDITIONAL_JAVA_ARGS="$ADDITIONAL_JAVA_ARGS -Djava.awt.headless=true" PLATFORM=`uname` SED_ARGS="-i" if [[ $PLATFORM == "Darwin" ]]; then SED_ARGS="-i \"\"" fi if [[ $PLATFORM != "Darwin" ]]; then TELNET_ACTIVE=`netstat -tlnp 2>/dev/null | grep ":$SERVER_PORT"` else TELNET_ACTIVE=`netstat -an 2>/dev/null | grep ".$SERVER_PORT"` fi if [[ $TELNET_ACTIVE != "" ]]; then echo "There is something already running on port $SERVER_PORT. Perhaps your server that has not been stopped?" exit fi scriptdir=`dirname "$0"` LIB_DIR="$PWD/native-libraries" if [[ ! -d "$PWD/logs" ]]; then mkdir logs fi if [[ ! -d "$PWD/tmp" ]]; then mkdir tmp fi echo "Script directory is $scriptdir and LIB_DIR is $LIB_DIR" # Make really sure that parameters from config.ini are not used sed $SED_ARGS "/mongo.host/d" ./configuration/config.ini sed $SED_ARGS "/mongo.port/d" ./configuration/config.ini sed $SED_ARGS "/expedition.udp.port/d" ./configuration/config.ini sed $SED_ARGS "/replication.exchangeName/d" ./configuration/config.ini sed $SED_ARGS "/replication.exchangeHost/d" ./configuration/config.ini # Ensure that Jetty Port is set correctly sed $SED_ARGS "s/^.*jetty.http.port.*$/<\/Set>/g" ./configuration/jetty/etc/jetty-http.xml # Update monitoring with the right ports sed $SED_ARGS "s/127.0.0.1:[0-9][0-9][0-9][0-9]\//127.0.0.1:$SERVER_PORT\//g" ./configuration/monitoring.properties # Inject information for system HEAD_DATE=$(date "+%Y%m%d%H%M") sed $SED_ARGS "s/System:.*$/ System: $MONGODB_HOST:$MONGODB_PORT\/$MONGODB_NAME-$EXPEDITION_PORT-$REPLICATION_HOST:$REPLICATION_PORT\/$REPLICATION_CHANNEL Started: $HEAD_DATE/g" ./configuration/jetty/version.txt # Apply app parameters from env.sh APP_PARAMETERS="-Dmongo.host=$MONGODB_HOST -Dmongo.port=$MONGODB_PORT -Dmongo.dbName=$MONGODB_NAME -Dexpedition.udp.port=$EXPEDITION_PORT -Dreplication.exchangeHost=$REPLICATION_HOST -Dreplication.exchangePort=$REPLICATION_PORT -Dreplication.exchangeName=$REPLICATION_CHANNEL" # Apply parameters for automatic replication start REPLICATION_PARAMETERS="-Dreplicate.on.start=$REPLICATE_ON_START -Dreplicate.master.servlet.host=$REPLICATE_MASTER_SERVLET_HOST -Dreplicate.master.servlet.port=$REPLICATE_MASTER_SERVLET_PORT -Dreplicate.master.queue.host=$REPLICATE_MASTER_QUEUE_HOST -Dreplicate.master.queue.port=$REPLICATE_MASTER_QUEUE_PORT -Dreplicate.master.exchange.name=$REPLICATE_MASTER_EXCHANGE_NAME" if [[ $PARAM == "" ]] || [[ $PARAM == "no-update" ]]; then nohup $JAVA_BINARY -D$SERVER_NAME $ADDITIONAL_JAVA_ARGS -Dcom.sap.sailing.server.name=$SERVER_NAME $APP_PARAMETERS $REPLICATION_PARAMETERS -Djava.io.tmpdir="$PWD/tmp" -Dfile.encoding=cp1252 -Djetty.home=$scriptdir/configuration/jetty -Djava.util.logging.config.file=$scriptdir/configuration/logging.properties -Djava.library.path=$LIB_DIR -Dosgi.shell.telnet.port=$TELNET_PORT -Xmx$MEMORY -jar plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar -configuration ./ -clean 2>/dev/null >/dev/null & JAVA_PID=$! echo "Starting server... (PID: $JAVA_PID)" echo "SERVER_NAME: $SERVER_NAME" echo "SERVER_PORT: $SERVER_PORT" echo "MEMORY: $MEMORY" echo "TELNET_PORT: $TELNET_PORT" echo "MONGODB_HOST: $MONGODB_HOST" echo "MONGODB_PORT: $MONGODB_PORT" echo "MONGODB_NAME: $MONGODB_NAME" echo "EXPEDITION_PORT: $EXPEDITION_PORT" echo "REPLICATION_CHANNEL: $REPLICATION_CHANNEL" echo $JAVA_PID > server.pid if [[ ! -z "$ON_AMAZON" ]]; then # give instances on amazon more time to start because # they may be influenced by the server's boot process echo "Be aware of the fact that starting amazon instances takes up to two minutes!" sleep 15 echo "Your instance should now be ready - waiting some more minutes before checking state..." sleep 120 else sleep 10 fi if [[ $PLATFORM != "Darwin" ]]; then SERVER_ACTIVE=`netstat -tlnp 2>/dev/null | grep ":$SERVER_PORT"` NETSTAT_INFO=`netstat -ntpl 2>/dev/null` else SERVER_ACTIVE=`netstat -an 2>/dev/null | grep ":$SERVER_PORT"` NETSTAT_INFO="" fi PROCESS_INFO=`ps auxwww` if [[ $PLATFORM != "Darwin" ]]; then if [[ $SERVER_PORT == "" ]] || [[ $SERVER_ACTIVE == "" ]]; then echo "Something went wrong with startup. Please check the logs..." if [[ $SERVER_STARTUP_NOTIFY != "" ]]; then echo "Startup of java server failed - check the logs ($SERVER_ACTIVE)\n\n$NETSTAT\n$PROCESS_INFO" | mail -r simon.marcel.pamies@sap.com -s "Server $INSTANCE_ID startup failed!" $SERVER_STARTUP_NOTIFY fi exit fi fi echo "Started $SERVER_NAME - use telnet localhost $TELNET_PORT to connect to the OSGi console. Logs should be found in logs/sailing0.log.0" if [[ $SERVER_STARTUP_NOTIFY != "" ]]; then if [[ ! -z "$ON_AMAZON" ]]; then echo "Go to http://$INSTANCE_DNS:$SERVER_PORT to reach your instance!" | mail -s "Server $INSTANCE_ID started up!" -a env.sh $SERVER_STARTUP_NOTIFY else echo "OK" | mail -s "Server $INSTANCE_ID started up!" -a env.sh $SERVER_STARTUP_NOTIFY fi fi elif [[ $PARAM == "debug" ]]; then echo "Starting remote debugging session on port 8000 - make sure this port is open and reachable from the outside" $JAVA_BINARY -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=y -D$SERVER_NAME -Dorg.osgi.framework.system.capabilities="osgi.ee; osgi.ee=\"JavaSE\";version:List=\"1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,1.10,1.11\"" $ADDITIONAL_JAVA_ARGS -Dcom.sap.sailing.server.name=$SERVER_NAME $APP_PARAMETERS $REPLICATION_PARAMETERS -Djava.io.tmpdir="$PWD/tmp" -Dfile.encoding=cp1252 -Djetty.home=$scriptdir/configuration/jetty -Djava.util.logging.config.file=$scriptdir/configuration/logging.properties -Djava.library.path=$LIB_DIR -Xmx$MEMORY -jar plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar -console -configuration ./ -clean elif [[ $PARAM == "fg" ]]; then $JAVA_BINARY -D$SERVER_NAME -Dorg.osgi.framework.system.capabilities="osgi.ee; osgi.ee=\"JavaSE\";version:List=\"1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,1.10,1.11\"" $ADDITIONAL_JAVA_ARGS -Dcom.sap.sailing.server.name=$SERVER_NAME $APP_PARAMETERS $REPLICATION_PARAMETERS -Djava.io.tmpdir="$PWD/tmp" -Dfile.encoding=cp1252 -Djetty.home=$scriptdir/configuration/jetty -Djava.util.logging.config.file=$scriptdir/configuration/logging.properties -Djava.library.path=$LIB_DIR -Xmx$MEMORY -jar plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar -console -configuration ./ -clean fi