#!/bin/sh # # Copyright (c) 2011-2012 EBM WebSourcing, 2012-2024 Linagora # # This program/library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 2.1 of the License, or (at your # option) any later version. # # This program/library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License # for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program/library; If not, see http://www.gnu.org/licenses/ # for the GNU Lesser General Public License version 2.1. # ################################################################################ # # Petals ESB Bootstrap Script # # Environment variables: # # JAVA_HOME Directory containing the JRE. Use the java executable # found in $PATH if not defined. # # JAVA_OPTS Options for the JVM. Try "java -h" to get informations # about the available options for your environment # # PETALS_CLASSPATH Extra classpath entries for the system classloader. # Careful because they will be visible by the whole JVM. # ############################################################################# # Set the path to the java executable JAVA="$JAVA_HOME/bin/java" [ -x "$JAVA" ] || JAVA="`which java`" || { echo "ERROR: java executable not found" >&2 exit 1 } PETALS_LIB_DIR="/usr/share/petals-esb" PETALS_EXT_DIR="$PETALS_LIB_DIR/extensions" PETALS_SYSEXT_DIR="$PETALS_LIB_DIR/system-extensions" # Set the path to petals launcher jar PETALS_LAUNCHER_PATTERN="petals-launcher-default-*.jar" PETALS_LAUNCHER_ARTIFACT=$(ls -1 $PETALS_LIB_DIR/$PETALS_LAUNCHER_PATTERN 2>/dev/null) # Check that the JAR is defined once if [ -z "$PETALS_LAUNCHER_ARTIFACT" ]; then echo "ERROR: No Petals launcher found in directory '$PETALS_LIB_DIR'. Pattern was: $PETALS_LAUNCHER_PATTERN" >&2 exit 1 fi # And only once! if [ "$(echo "$PETALS_LAUNCHER_ARTIFACT" | wc -l)" -ne 1 ]; then echo -e "ERROR: Several Petals launcher versions were found in $PETALS_LIB_DIR:\n$PETALS_LAUNCHER_ARTIFACT" >&2 exit 1 fi # classpath PETALS_BOOTSTRAP_PATTERN="petals-bootstrap-launcher-*.jar" PETALS_BOOTSTRAP_ARTIFACT="$(ls -1 $PETALS_LIB_DIR/$PETALS_BOOTSTRAP_PATTERN 2>/dev/null)" # Check that the JAR is defined once if [ -z "$PETALS_BOOTSTRAP_ARTIFACT" ]; then echo "ERROR: Petals Bootstrap Launcher not found in $PETALS_LIB_DIR. Pattern was: $PETALS_BOOTSTRAP_PATTERN" >&2 exit 1 fi # And only once! if [ "$(echo "$PETALS_BOOTSTRAP_ARTIFACT" | wc -l)" -ne 1 ]; then echo -e "ERROR: Several Petals Bootstrap Launcher versions were found in $PETALS_LIB_DIR:\n$PETALS_BOOTSTRAP_ARTIFACT" >&2 exit 1 fi PETALS_CLASSPATH="$PETALS_BOOTSTRAP_ARTIFACT:$PETALS_SYSEXT_DIR:$PETALS_CLASSPATH" # Petals options PETALS_OPTS="-Dpetals.lib.dir=$PETALS_LIB_DIR -Dpetals.ext.dir=$PETALS_EXT_DIR" # Petals arguments PETALS_ARGS="" HELP_FLAG="" VERSION_FLAG="" SERVER_PROPERTIES_URL="" while getopts ':dehu:V' OPT; do case "$OPT" in d) DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=y" ;; e) PETALS_ARGS="$PETALS_ARGS -e" ;; h) HELP_FLAG="yes" PETALS_ARGS="$PETALS_ARGS -h" ;; u) SERVER_PROPERTIES_URL="$OPTARG" PETALS_ARGS="$PETALS_ARGS -u $SERVER_PROPERTIES_URL" ;; V) VERSION_FLAG="yes" PETALS_ARGS="$PETALS_ARGS -V" ;; *) PETALS_ARGS="$PETALS_ARGS $OPT $OPTARG" ;; esac done PETALS_STOP_ASKED="false" `echo "$@" | grep -qE "stop$"` && { PETALS_ARGS="$PETALS_ARGS stop" PETALS_STOP_ASKED="true" } [ ! -z "$HELP_FLAG" ] || [ ! -z "$VERSION_FLAG" ] || { # Retrieve the environment configuration if [ -z "$SERVER_PROPERTIES_URL" ]; then echo "Error: You must specify a container configuration URL using '-u '." >&2 exit 1 fi LOCAL_SERVER_PROPERTIES="/tmp/petals-local-server.$$.properties" `curl -s $SERVER_PROPERTIES_URL > $LOCAL_SERVER_PROPERTIES` if [ $? -ne 0 ]; then echo "Error retrieving the local container configuration: $SERVER_PROPERTIES_URL" >&2 exit 1; fi ENV_CFG_FILE=`sed "/^\#/d" $LOCAL_SERVER_PROPERTIES | grep "petals.environment.config.file" | cut -d "=" -f2- | sed "s/^[[:space:]]*//;s/[[:space:]]*$//"` rm -f $LOCAL_SERVER_PROPERTIES >&2 if [ -z "$ENV_CFG_FILE" ]; then . /etc/petals-esb/default-env.sh else case "$ENV_CFG_FILE" in /*) # Absolute environment configuration file . $ENV_CFG_FILE ;; *) # Relative environment configuration file FILE_SCHEME=`echo $SERVER_PROPERTIES_URL | sed -e "s/^file:\/\/\(.*\)/\1/"` if [ -z $FILE_SCHEME ]; then echo "Relative environment configuration file is authorized only for local url (ie. file://...)" >&2 exit 1; else . `dirname $FILE_SCHEME`/$ENV_CFG_FILE fi ;; esac fi } # Start exec "$JAVA" -classpath $PETALS_CLASSPATH $JAVA_OPTS $PETALS_OPTS $DEBUG_OPTS org.ow2.petals.BootstrapLauncher $PETALS_LAUNCHER_ARTIFACT $PETALS_ARGS