start-ds revision 9da44d3de0a7180285a77b7e8d2426a72aca249e
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#!/bin/sh
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# CDDL HEADER START
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# The contents of this file are subject to the terms of the
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Common Development and Distribution License, Version 1.0 only
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# (the "License"). You may not use this file except in compliance
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# with the License.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# You can obtain a copy of the license at
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# trunk/opends/resource/legal-notices/OpenDS.LICENSE
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# See the License for the specific language governing permissions
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# and limitations under the License.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# When distributing Covered Code, include this CDDL HEADER in each
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# file and include the License file at
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# add the following below this CDDL HEADER, with the fields enclosed
f71f7a61dec7c9089378d14493ad564a1dedf0b5neil_a_wilson# by brackets "[]" replaced with your own identifying information:
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Portions Copyright [yyyy] [name of copyright owner]
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# CDDL HEADER END
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilson# Portions Copyright 2006-2007 Sun Microsystems, Inc.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson# Capture the current working directory so that we can change to it later.
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson# Then capture the location of this script and the Directory Server instance
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson# root so that we can use them to create appropriate paths.
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilsonWORKING_DIR=`pwd`
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilsoncd `dirname "${0}"`
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilsonSCRIPT_DIR=`pwd`
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilsoncd ..
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilsonINSTANCE_ROOT=`pwd`
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilsonexport INSTANCE_ROOT
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilsoncd "${WORKING_DIR}"
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# See if JAVA_HOME is set. If not, then see if there is a java executable in
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# the path and try to figure it out.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeif test -z "${JAVA_BIN}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipethen
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe if test -z "${JAVA_HOME}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
9da44d3de0a7180285a77b7e8d2426a72aca249ejvergara if test -f "${INSTANCE_ROOT}/lib/set-java-home"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
9da44d3de0a7180285a77b7e8d2426a72aca249ejvergara . "${INSTANCE_ROOT}/lib/set-java-home"
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson JAVA_BIN="${JAVA_HOME}/bin/java"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe export JAVA_BIN
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe else
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson JAVA_BIN=`which java 2> /dev/null`
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson if test ${?} -eq 0
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson then
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson export JAVA_BIN
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson else
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson exit 1
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe else
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson JAVA_BIN="${JAVA_HOME}/bin/java"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe export JAVA_BIN
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipefi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# system environment variables for security and compatibility reasons.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipePATH=/bin:/usr/bin
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_LIBRARY_PATH=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_LIBRARY_PATH_32=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_LIBRARY_PATH_64=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_PRELOAD=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_PRELOAD_32=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_PRELOAD_64=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Configure the appropriate CLASSPATH.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeCLASSPATH=${INSTANCE_ROOT}/classes
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipefor JAR in ${INSTANCE_ROOT}/lib/*.jar
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipedo
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe CLASSPATH=${CLASSPATH}:${JAR}
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipedone
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeexport CLASSPATH
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Specify the locations of important files that may be used when the server
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# is starting.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeCONFIG_FILE=${INSTANCE_ROOT}/config/config.ldif
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipePID_FILE=${INSTANCE_ROOT}/logs/server.pid
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLOG_FILE=${INSTANCE_ROOT}/logs/server.out
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeSTARTING_FILE=${INSTANCE_ROOT}/logs/server.starting
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
266c5071a91fda6a5159b08ea8d45261228d03d5neil_a_wilson# Specify the script name so that it may be provided in command-line usage.
266c5071a91fda6a5159b08ea8d45261228d03d5neil_a_wilsonSCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=start-ds"
266c5071a91fda6a5159b08ea8d45261228d03d5neil_a_wilsonexport SCRIPT_NAME_ARG
266c5071a91fda6a5159b08ea8d45261228d03d5neil_a_wilson
39e085accf228684b9573bc8ad707a364ed6242ejvergara# Test that the provided JDK is 1.5 compatible.
39e085accf228684b9573bc8ad707a364ed6242ejvergaraif test -z "${JAVA_ARGS}"
39e085accf228684b9573bc8ad707a364ed6242ejvergarathen
39e085accf228684b9573bc8ad707a364ed6242ejvergara "${JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
39e085accf228684b9573bc8ad707a364ed6242ejvergara if test ${?} -ne 0
39e085accf228684b9573bc8ad707a364ed6242ejvergara then
39e085accf228684b9573bc8ad707a364ed6242ejvergara echo "ERROR: The detected Java version could not be used. Please set "
39e085accf228684b9573bc8ad707a364ed6242ejvergara echo " JAVA_HOME to the root of a Java 5.0 installation."
39e085accf228684b9573bc8ad707a364ed6242ejvergara exit 1
39e085accf228684b9573bc8ad707a364ed6242ejvergara fi
39e085accf228684b9573bc8ad707a364ed6242ejvergaraelse
39e085accf228684b9573bc8ad707a364ed6242ejvergara "${JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
39e085accf228684b9573bc8ad707a364ed6242ejvergara if test ${?} -ne 0
39e085accf228684b9573bc8ad707a364ed6242ejvergara then
39e085accf228684b9573bc8ad707a364ed6242ejvergara echo "ERROR: The detected Java version could not be used with the specified"
39e085accf228684b9573bc8ad707a364ed6242ejvergara echo "Java arguments. Please set JAVA_HOME to the root of a Java 5.0 installation."
39e085accf228684b9573bc8ad707a364ed6242ejvergara exit 1
39e085accf228684b9573bc8ad707a364ed6242ejvergara fi
39e085accf228684b9573bc8ad707a364ed6242ejvergarafi
266c5071a91fda6a5159b08ea8d45261228d03d5neil_a_wilson
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilson# See if the provided set of arguments were sufficient for us to be able to
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilson# start the server or perform the requested operation. An exit code of 99
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilson# means that it should be possible to start the server. An exit code of 98
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilson# means that the server is already running and we shouldn't try to start it.
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilson# An exit code of anything else means that we're not trying to start the server
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilson# and we can just exit with that exit code.
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilson${JAVA_BIN} ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilson --configClass org.opends.server.extensions.ConfigFileHandler \
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilson --configFile "${CONFIG_FILE}" --checkStartability "${@}"
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilsonEC=${?}
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraif test ${EC} -eq 99
5c6cfc2988a5121fd22081643ef0790e38c99379neil_a_wilsonthen
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
7070667c2dffad87009999bdeb16d5305e0afdbejvergara # run detach
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe touch "${STARTING_FILE}"
266c5071a91fda6a5159b08ea8d45261228d03d5neil_a_wilson nohup "${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe org.opends.server.core.DirectoryServer \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe --configClass org.opends.server.extensions.ConfigFileHandler \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe --configFile "${CONFIG_FILE}" "${@}" > "${LOG_FILE}" 2>&1 &
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe echo $! > "${PID_FILE}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe "${JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe --targetFile "${STARTING_FILE}" --logFile "${LOG_FILE}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe exit ${?}
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraelse
7070667c2dffad87009999bdeb16d5305e0afdbejvergara if test ${EC} -eq 100
7070667c2dffad87009999bdeb16d5305e0afdbejvergara then
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
7070667c2dffad87009999bdeb16d5305e0afdbejvergara # run no detach
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
7070667c2dffad87009999bdeb16d5305e0afdbejvergara echo $$ > "${PID_FILE}"
4afc3f189bd46ee59828c326a83684969dc39d80neil_a_wilson rm -f "${LOG_FILE}"
7070667c2dffad87009999bdeb16d5305e0afdbejvergara exec "${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
7070667c2dffad87009999bdeb16d5305e0afdbejvergara org.opends.server.core.DirectoryServer \
7070667c2dffad87009999bdeb16d5305e0afdbejvergara --configClass org.opends.server.extensions.ConfigFileHandler \
7070667c2dffad87009999bdeb16d5305e0afdbejvergara --configFile "${CONFIG_FILE}" "${@}"
7070667c2dffad87009999bdeb16d5305e0afdbejvergara else
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
7070667c2dffad87009999bdeb16d5305e0afdbejvergara # an error or the server is already started. Just return the code provided
7070667c2dffad87009999bdeb16d5305e0afdbejvergara # by checkstartability
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
7070667c2dffad87009999bdeb16d5305e0afdbejvergara exit ${EC}
7070667c2dffad87009999bdeb16d5305e0afdbejvergara fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipefi