start-ds revision 2650
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller#!/bin/sh
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller#
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# CDDL HEADER START
0ab07c6ace6fcb4437776e716a96749c8f5f90e6Alin Brici#
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# The contents of this file are subject to the terms of the
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# Common Development and Distribution License, Version 1.0 only
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# (the "License"). You may not use this file except in compliance
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# with the License.
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller#
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# You can obtain a copy of the license at
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# trunk/opends/resource/legal-notices/OpenDS.LICENSE
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# See the License for the specific language governing permissions
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# and limitations under the License.
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller#
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# When distributing Covered Code, include this CDDL HEADER in each
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# file and include the License file at
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# add the following below this CDDL HEADER, with the fields enclosed
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# by brackets "[]" replaced with your own identifying information:
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# Portions Copyright [yyyy] [name of copyright owner]
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller#
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# CDDL HEADER END
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch#
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch#
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch# Portions Copyright 2006-2007 Sun Microsystems, Inc.
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay# Capture the current working directory so that we can change to it later.
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch# Then capture the location of this script and the Directory Server instance
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay# root so that we can use them to create appropriate paths.
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason LemayWORKING_DIR=`pwd`
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmillercd `dirname "${0}"`
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan MmillerSCRIPT_DIR=`pwd`
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmillercd ..
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan MmillerINSTANCE_ROOT=`pwd`
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmillerexport INSTANCE_ROOT
f4499844e2092e1a97238a393361ff879f13fe15Laurent Bristiel
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmillercd "${WORKING_DIR}"
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# See if the environment variables are set. If not, then see if there is a java
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller# executable in the path and try to figure it out.
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branchif test -z "${OPENDS_JAVA_BIN}"
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmillerthen
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason Lemay if test -z "${OPENDS_JAVA_HOME}"
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch then
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller if test -f "${INSTANCE_ROOT}/lib/set-java-home"
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch then
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason Lemay . "${INSTANCE_ROOT}/lib/set-java-home"
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason Lemay OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason Lemay export OPENDS_JAVA_BIN
8013147372959d2435f1f8b0305057cfce308168Jason Lemay else
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay if test -z "${JAVA_BIN}"
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason Lemay then
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason Lemay if test -z "${JAVA_HOME}"
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason Lemay then
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason Lemay OPENDS_JAVA_BIN=`which java 2> /dev/null`
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason Lemay if test ${?} -eq 0
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason Lemay then
7f6887b5c5e1d621fbbb48d93b8ac940521d1e38Jason Lemay export OPENDS_JAVA_BIN
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller else
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch exit 1
439aeca927c6a5e03e71c880e729b3143ebc538cJason Lemay fi
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay else
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay OPENDS_JAVA_BIN="${JAVA_HOME}/bin/java"
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay export OPENDS_JAVA_BIN
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay fi
439aeca927c6a5e03e71c880e729b3143ebc538cJason Lemay else
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch OPENDS_JAVA_BIN="${JAVA_BIN}"
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch export OPENDS_JAVA_BIN
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch fi
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch fi
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay else
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay export OPENDS_JAVA_BIN
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay fi
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemayfi
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch# system environment variables for security and compatibility reasons.
0f63005dc454e8131506be734dc0404f48c8578cJason LemayPATH=/bin:/usr/bin
0f63005dc454e8131506be734dc0404f48c8578cJason LemayLD_LIBRARY_PATH=
dc357eedd51bb456915886c03247ac04d497ce2bJason LemayLD_LIBRARY_PATH_32=
dc357eedd51bb456915886c03247ac04d497ce2bJason LemayLD_LIBRARY_PATH_64=
dc357eedd51bb456915886c03247ac04d497ce2bJason LemayLD_PRELOAD=
dc357eedd51bb456915886c03247ac04d497ce2bJason LemayLD_PRELOAD_32=
dc357eedd51bb456915886c03247ac04d497ce2bJason LemayLD_PRELOAD_64=
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemayexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay# Configure the appropriate CLASSPATH.
dc357eedd51bb456915886c03247ac04d497ce2bJason LemayCLASSPATH=${INSTANCE_ROOT}/classes
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemayfor JAR in ${INSTANCE_ROOT}/lib/*.jar
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemaydo
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay CLASSPATH=${CLASSPATH}:${JAR}
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemaydone
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemayexport CLASSPATH
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch# Specify the locations of important files that may be used when the server
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay# is starting.
548846fe158900a483ca91f47603c6bb6fde9b47Jon BranchCONFIG_FILE=${INSTANCE_ROOT}/config/config.ldif
0f63005dc454e8131506be734dc0404f48c8578cJason LemayPID_FILE=${INSTANCE_ROOT}/logs/server.pid
dc357eedd51bb456915886c03247ac04d497ce2bJason LemayLOG_FILE=${INSTANCE_ROOT}/logs/server.out
dc357eedd51bb456915886c03247ac04d497ce2bJason LemaySTARTING_FILE=${INSTANCE_ROOT}/logs/server.starting
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch# Specify the script name so that it may be provided in command-line usage.
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan MmillerSCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=start-ds"
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branchexport SCRIPT_NAME_ARG
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay# Test that the provided JDK is 1.5 compatible.
0f63005dc454e8131506be734dc0404f48c8578cJason Lemayif test -z "${JAVA_ARGS}"
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branchthen
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch if test ${?} -ne 0
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch then
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch echo "ERROR: The detected Java version could not be used. Please ensure"
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay echo " that OPENDS_JAVA_HOME is set to the root of a valid Java 5.0 or"
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch echo " higher installation."
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch exit 1
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch fi
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branchelse
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch if test ${?} -ne 0
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch then
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch echo "ERROR: The detected Java version could not be used with the"
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay echo " set of arguments. Please ensure that OPENDS_JAVA_HOME is"
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay echo " set to the root of a valid Java 5.0 or higher installation, and"
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay echo " make sure that JAVA_ARGS contains a valid set of arguments"
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch echo " for that JVM."
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch exit 1
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch fi
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmillerfi
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch# See if the provided set of arguments were sufficient for us to be able to
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay# start the server or perform the requested operation. An exit code of 99
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay# means that it should be possible to start the server. An exit code of 98
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay# means that the server is already running and we shouldn't try to start it.
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay# An exit code of anything else means that we're not trying to start the server
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch# and we can just exit with that exit code.
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch${OPENDS_JAVA_BIN} ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch --configClass org.opends.server.extensions.ConfigFileHandler \
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch --configFile "${CONFIG_FILE}" --checkStartability "${@}"
0f63005dc454e8131506be734dc0404f48c8578cJason LemayEC=${?}
0f63005dc454e8131506be734dc0404f48c8578cJason Lemayif test ${EC} -eq 99 -o ${EC} -eq 103
0f63005dc454e8131506be734dc0404f48c8578cJason Lemaythen
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay #
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay # run detach
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch #
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay touch "${STARTING_FILE}"
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay nohup "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay org.opends.server.core.DirectoryServer \
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay --configClass org.opends.server.extensions.ConfigFileHandler \
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay --configFile "${CONFIG_FILE}" "${@}" > "${LOG_FILE}" 2>&1 &
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay echo $! > "${PID_FILE}"
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay if test ${EC} -eq 99
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay then
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch --targetFile "${STARTING_FILE}" --logFile "${LOG_FILE}"
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch else
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay --targetFile "${STARTING_FILE}"
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay fi
dc357eedd51bb456915886c03247ac04d497ce2bJason Lemay EC=${?}
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch if test ${EC} -eq 0
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch then
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch # An exit code of 98 means that the server is already running.
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch ${OPENDS_JAVA_BIN} ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
7dcb2f62e25d05f2afeb4e79f10102350d7c2c7bBrendan Mmiller --configClass org.opends.server.extensions.ConfigFileHandler \
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch --configFile "${CONFIG_FILE}" --checkStartability > /dev/null 2>&1
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch EC=${?}
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay if test ${EC} -eq 98
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch then
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch exit 0
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay else
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch # Could not start the server
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch exit 1
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch fi
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch fi
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch exit ${?}
0f63005dc454e8131506be734dc0404f48c8578cJason Lemayelse
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay if test ${EC} -eq 100
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay then
0f63005dc454e8131506be734dc0404f48c8578cJason Lemay #
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch # run no detach
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch #
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch echo $$ > "${PID_FILE}"
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch rm -f "${LOG_FILE}"
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch exec "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch org.opends.server.core.DirectoryServer \
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch --configClass org.opends.server.extensions.ConfigFileHandler \
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch --configFile "${CONFIG_FILE}" "${@}"
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch else
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch #
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch # an error or the server is already started. Just return the code provided
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch # by checkstartability
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch #
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch exit ${EC}
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch fi
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branchfi
548846fe158900a483ca91f47603c6bb6fde9b47Jon Branch