start-ds revision 619
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#!/bin/sh
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# CDDL HEADER START
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# The contents of this file are subject to the terms of the
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Common Development and Distribution License, Version 1.0 only
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# (the "License"). You may not use this file except in compliance
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# with the License.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# You can obtain a copy of the license at
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# trunk/opends/resource/legal-notices/OpenDS.LICENSE
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# See the License for the specific language governing permissions
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# and limitations under the License.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# When distributing Covered Code, include this CDDL HEADER in each
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# file and include the License file at
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# add the following below this CDDL HEADER, with the fields enclosed
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# by brackets "[]" replaced with your own identifying * information:
6398f22526303343193a18e514602f1af6fb29cbNikolai Kondrashov# Portions Copyright [yyyy] [name of copyright owner]
6398f22526303343193a18e514602f1af6fb29cbNikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# CDDL HEADER END
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov#
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Portions Copyright 2006 Sun Microsystems, Inc.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Capture the current working directory so that we can change to it later.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Then capture the location of this script and the Directory Server instance
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# root so that we can use them to create appropriate paths.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovWORKING_DIR=`pwd`
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovcd `dirname "${0}"`
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovSCRIPT_DIR=`pwd`
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovcd ..
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovINSTANCE_ROOT=`pwd`
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovexport INSTANCE_ROOT
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovcd "${WORKING_DIR}"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# See if JAVA_HOME is set. If not, then see if there is a java executable in
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# the path and try to figure it out.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovif test -z "${JAVA_BIN}"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovthen
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov if test -z "${JAVA_HOME}"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov then
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov if test -f "${INSTANCE_ROOT}/bin/set-java-home"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov then
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov . "${INSTANCE_ROOT}/bin/set-java-home"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov JAVA_BIN="${JAVA_HOME}/bin/java"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov export JAVA_BIN
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov else
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov JAVA_BIN=`which java 2> /dev/null`
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov if test ${?} -eq 0
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov then
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov export JAVA_BIN
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov else
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov exit 1
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov fi
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov fi
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov else
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov JAVA_BIN="${JAVA_HOME}/bin/java"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov export JAVA_BIN
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov fi
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovfi
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# system environment variables for security and compatibility reasons.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovPATH=/bin:/usr/bin
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovLD_LIBRARY_PATH=
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovLD_LIBRARY_PATH_32=
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovLD_LIBRARY_PATH_64=
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovLD_PRELOAD=
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovLD_PRELOAD_32=
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovLD_PRELOAD_64=
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Configure the appropriate CLASSPATH.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovCLASSPATH=${INSTANCE_ROOT}/classes
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovfor JAR in ${INSTANCE_ROOT}/lib/*.jar
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovdo
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov CLASSPATH=${CLASSPATH}:${JAR}
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovdone
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovexport CLASSPATH
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Specify the locations of important files that may be used when the server
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# is starting.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovCONFIG_FILE=${INSTANCE_ROOT}/config/config.ldif
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovPID_FILE=${INSTANCE_ROOT}/logs/server.pid
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovLOG_FILE=${INSTANCE_ROOT}/logs/server.out
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovSTARTING_FILE=${INSTANCE_ROOT}/logs/server.starting
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Specify the script name so that it may be provided in command-line usage.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovSCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=start-ds"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovexport SCRIPT_NAME_ARG
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# See if an "-N" or a "--nodetach" argument was provided as a command-line
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# argument. If it was, then don't use nohup to send to the background, and
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# send all output to both the console and a lot file.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai KondrashovNODETACH=0
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovfor ARG in "${@}"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovdo
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov if test "${ARG}" = "-N"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov then
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov NODETACH=1
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov else
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov ARG=`echo ${ARG} | tr '[A-Z]' '[a-z]'`
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov if test "${ARG}" = "--nodetach"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov then
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov NODETACH=1
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov fi
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov fi
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovdone
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovif test ${NODETACH} -eq 1
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovthen
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov echo $$ > "${PID_FILE}"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov rm -f "${PID_FILE}" "${LOG_FILE}"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov exec "${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov org.opends.server.core.DirectoryServer \
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov --configClass org.opends.server.extensions.ConfigFileHandler \
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov --configFile "${CONFIG_FILE}" "${@}"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovelse
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov touch "${STARTING_FILE}"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov nohup "${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov org.opends.server.core.DirectoryServer \
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov --configClass org.opends.server.extensions.ConfigFileHandler \
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov --configFile "${CONFIG_FILE}" "${@}" > "${LOG_FILE}" 2>&1 &
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov echo $! > "${PID_FILE}"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov "${JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov --targetFile "${STARTING_FILE}" --logFile "${LOG_FILE}"
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov exit ${?}
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovfi
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov