start-ds revision fbae67e0ce2395d66b4cec5b17c54ddf8dd3dcb2
e334405421979688f2d838805ac67ee47bd62976Mark Andrews#!/bin/sh
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
b8a9a7bef2c3060204c68aef4f3fce04afc1aaeeAutomatic Updater# CDDL HEADER START
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# The contents of this file are subject to the terms of the
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Common Development and Distribution License, Version 1.0 only
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# (the "License"). You may not use this file except in compliance
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# with the License.
c1aef54e14bb92518b1c062ba8c0292a7cb949cbAutomatic Updater#
b8a9a7bef2c3060204c68aef4f3fce04afc1aaeeAutomatic Updater# You can obtain a copy of the license at
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# trunk/opends/resource/legal-notices/OpenDS.LICENSE
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# See the License for the specific language governing permissions
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# and limitations under the License.
e334405421979688f2d838805ac67ee47bd62976Mark Andrews#
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# When distributing Covered Code, include this CDDL HEADER in each
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# file and include the License file at
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# add the following below this CDDL HEADER, with the fields enclosed
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# by brackets "[]" replaced with your own identifying information:
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# Portions Copyright [yyyy] [name of copyright owner]
e334405421979688f2d838805ac67ee47bd62976Mark Andrews#
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# CDDL HEADER END
e334405421979688f2d838805ac67ee47bd62976Mark Andrews#
e334405421979688f2d838805ac67ee47bd62976Mark Andrews#
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# Portions Copyright 2006-2007 Sun Microsystems, Inc.
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# Capture the current working directory so that we can change to it later.
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# Then capture the location of this script and the Directory Server instance
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# root so that we can use them to create appropriate paths.
e334405421979688f2d838805ac67ee47bd62976Mark AndrewsWORKING_DIR=`pwd`
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
b8a9a7bef2c3060204c68aef4f3fce04afc1aaeeAutomatic Updatercd `dirname "${0}"`
e334405421979688f2d838805ac67ee47bd62976Mark AndrewsSCRIPT_DIR=`pwd`
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrewscd ..
e334405421979688f2d838805ac67ee47bd62976Mark AndrewsINSTANCE_ROOT=`pwd`
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsexport INSTANCE_ROOT
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrewscd "${WORKING_DIR}"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# See if JAVA_HOME is set. If not, then see if there is a java executable in
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# the path and try to figure it out.
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsif test -z "${JAVA_BIN}"
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsthen
e334405421979688f2d838805ac67ee47bd62976Mark Andrews if test -z "${JAVA_HOME}"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews then
e334405421979688f2d838805ac67ee47bd62976Mark Andrews if test -f "${INSTANCE_ROOT}/lib/set-java-home"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews then
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews . "${INSTANCE_ROOT}/lib/set-java-home"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews JAVA_BIN="${JAVA_HOME}/bin/java"
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews export JAVA_BIN
e334405421979688f2d838805ac67ee47bd62976Mark Andrews else
e334405421979688f2d838805ac67ee47bd62976Mark Andrews JAVA_BIN=`which java 2> /dev/null`
e334405421979688f2d838805ac67ee47bd62976Mark Andrews if test ${?} -eq 0
f2ea8c2f965be7ff4c59f805712c12d469226b7bEvan Hunt then
e334405421979688f2d838805ac67ee47bd62976Mark Andrews export JAVA_BIN
e334405421979688f2d838805ac67ee47bd62976Mark Andrews else
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo "ERROR: No Java installation could be found. Please set"
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews echo " JAVA_HOME to the root of a Java 5.0 or higher"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo " installation."
e334405421979688f2d838805ac67ee47bd62976Mark Andrews exit 1
e334405421979688f2d838805ac67ee47bd62976Mark Andrews fi
e334405421979688f2d838805ac67ee47bd62976Mark Andrews fi
e334405421979688f2d838805ac67ee47bd62976Mark Andrews else
f2ea8c2f965be7ff4c59f805712c12d469226b7bEvan Hunt JAVA_BIN="${JAVA_HOME}/bin/java"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews export JAVA_BIN
e334405421979688f2d838805ac67ee47bd62976Mark Andrews fi
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsfi
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews# system environment variables for security and compatibility reasons.
e334405421979688f2d838805ac67ee47bd62976Mark AndrewsPATH=/bin:/usr/bin
bfde61d5194a534d800f3b90008d1f52261922c5Mark AndrewsLD_LIBRARY_PATH=
bfde61d5194a534d800f3b90008d1f52261922c5Mark AndrewsLD_LIBRARY_PATH_32=
e334405421979688f2d838805ac67ee47bd62976Mark AndrewsLD_LIBRARY_PATH_64=
bfde61d5194a534d800f3b90008d1f52261922c5Mark AndrewsLD_PRELOAD=
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan HuntLD_PRELOAD_32=
bfde61d5194a534d800f3b90008d1f52261922c5Mark AndrewsLD_PRELOAD_64=
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews# Configure the appropriate CLASSPATH.
bfde61d5194a534d800f3b90008d1f52261922c5Mark AndrewsCLASSPATH=${INSTANCE_ROOT}/classes
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsfor JAR in ${INSTANCE_ROOT}/lib/*.jar
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrewsdo
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews CLASSPATH=${CLASSPATH}:${JAR}
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrewsdone
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrewsexport CLASSPATH
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews
bfde61d5194a534d800f3b90008d1f52261922c5Mark Andrews# Specify the locations of important files that may be used when the server
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# is starting.
44c0cfd2be65cebdfce66e0911c4da11186ee651Mark AndrewsCONFIG_FILE=${INSTANCE_ROOT}/config/config.ldif
e334405421979688f2d838805ac67ee47bd62976Mark AndrewsPID_FILE=${INSTANCE_ROOT}/logs/server.pid
e334405421979688f2d838805ac67ee47bd62976Mark AndrewsLOG_FILE=${INSTANCE_ROOT}/logs/server.out
e334405421979688f2d838805ac67ee47bd62976Mark AndrewsSTARTING_FILE=${INSTANCE_ROOT}/logs/server.starting
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# Specify the script name so that it may be provided in command-line usage.
e334405421979688f2d838805ac67ee47bd62976Mark AndrewsSCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=start-ds"
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsexport SCRIPT_NAME_ARG
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# Test that the provided JDK is 1.5 compatible.
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsif test -z "${JAVA_ARGS}"
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsthen
e334405421979688f2d838805ac67ee47bd62976Mark Andrews "${JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
e334405421979688f2d838805ac67ee47bd62976Mark Andrews if test ${?} -ne 0
e334405421979688f2d838805ac67ee47bd62976Mark Andrews then
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo "ERROR: The detected Java version could not be used. Please ensure"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo " that JAVA_HOME is set to the root of a valid Java 5.0 or"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo " higher installation."
e334405421979688f2d838805ac67ee47bd62976Mark Andrews exit 1
e334405421979688f2d838805ac67ee47bd62976Mark Andrews fi
e334405421979688f2d838805ac67ee47bd62976Mark Andrewselse
e334405421979688f2d838805ac67ee47bd62976Mark Andrews "${JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
e334405421979688f2d838805ac67ee47bd62976Mark Andrews if test ${?} -ne 0
e334405421979688f2d838805ac67ee47bd62976Mark Andrews then
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo "ERROR: The detected Java version could not be used with the"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo " set of arguments. Please ensure that JAVA_HOME is set to"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo " the root of a valid Java 5.0 or higher installation, and"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo " make sure that JAVA_ARGS contains a valid set of arguments"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo " for that JVM."
e334405421979688f2d838805ac67ee47bd62976Mark Andrews exit 1
e334405421979688f2d838805ac67ee47bd62976Mark Andrews fi
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsfi
e334405421979688f2d838805ac67ee47bd62976Mark Andrews
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# See if the provided set of arguments were sufficient for us to be able to
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# start the server or perform the requested operation. An exit code of 99
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# means that it should be possible to start the server. An exit code of 98
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# means that the server is already running and we shouldn't try to start it.
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# An exit code of anything else means that we're not trying to start the server
e334405421979688f2d838805ac67ee47bd62976Mark Andrews# and we can just exit with that exit code.
e334405421979688f2d838805ac67ee47bd62976Mark Andrews${JAVA_BIN} ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
e334405421979688f2d838805ac67ee47bd62976Mark Andrews --configClass org.opends.server.extensions.ConfigFileHandler \
e334405421979688f2d838805ac67ee47bd62976Mark Andrews --configFile "${CONFIG_FILE}" --checkStartability "${@}"
e334405421979688f2d838805ac67ee47bd62976Mark AndrewsEC=${?}
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsif test ${EC} -eq 99 -o ${EC} -eq 103
e334405421979688f2d838805ac67ee47bd62976Mark Andrewsthen
e334405421979688f2d838805ac67ee47bd62976Mark Andrews #
b8a9a7bef2c3060204c68aef4f3fce04afc1aaeeAutomatic Updater # run detach
e334405421979688f2d838805ac67ee47bd62976Mark Andrews #
e334405421979688f2d838805ac67ee47bd62976Mark Andrews touch "${STARTING_FILE}"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews nohup "${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
e334405421979688f2d838805ac67ee47bd62976Mark Andrews org.opends.server.core.DirectoryServer \
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt --configClass org.opends.server.extensions.ConfigFileHandler \
e334405421979688f2d838805ac67ee47bd62976Mark Andrews --configFile "${CONFIG_FILE}" "${@}" > "${LOG_FILE}" 2>&1 &
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo $! > "${PID_FILE}"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews if test ${EC} -eq 99
e334405421979688f2d838805ac67ee47bd62976Mark Andrews then
e334405421979688f2d838805ac67ee47bd62976Mark Andrews "${JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
e334405421979688f2d838805ac67ee47bd62976Mark Andrews --targetFile "${STARTING_FILE}" --logFile "${LOG_FILE}"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews else
e334405421979688f2d838805ac67ee47bd62976Mark Andrews "${JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
e334405421979688f2d838805ac67ee47bd62976Mark Andrews --targetFile "${STARTING_FILE}"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews fi
e334405421979688f2d838805ac67ee47bd62976Mark Andrews EC=${?}
e334405421979688f2d838805ac67ee47bd62976Mark Andrews if test ${EC} -eq 0
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt then
f2ea8c2f965be7ff4c59f805712c12d469226b7bEvan Hunt # An exit code of 98 means that the server is already running.
1e442d19949b84d448742672e2ed8cab1177abb6Mark Andrews ${JAVA_BIN} ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
1e442d19949b84d448742672e2ed8cab1177abb6Mark Andrews --configClass org.opends.server.extensions.ConfigFileHandler \
e334405421979688f2d838805ac67ee47bd62976Mark Andrews --configFile "${CONFIG_FILE}" --checkStartability
e334405421979688f2d838805ac67ee47bd62976Mark Andrews EC=${?}
e334405421979688f2d838805ac67ee47bd62976Mark Andrews if test ${EC} -eq 98
f2ea8c2f965be7ff4c59f805712c12d469226b7bEvan Hunt then
e334405421979688f2d838805ac67ee47bd62976Mark Andrews exit 0
e334405421979688f2d838805ac67ee47bd62976Mark Andrews else
e334405421979688f2d838805ac67ee47bd62976Mark Andrews # Could not start the server
e334405421979688f2d838805ac67ee47bd62976Mark Andrews exit 1
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt fi
e334405421979688f2d838805ac67ee47bd62976Mark Andrews fi
e334405421979688f2d838805ac67ee47bd62976Mark Andrews exit ${?}
e334405421979688f2d838805ac67ee47bd62976Mark Andrewselse
e334405421979688f2d838805ac67ee47bd62976Mark Andrews if test ${EC} -eq 100
e334405421979688f2d838805ac67ee47bd62976Mark Andrews then
e334405421979688f2d838805ac67ee47bd62976Mark Andrews #
e334405421979688f2d838805ac67ee47bd62976Mark Andrews # run no detach
e334405421979688f2d838805ac67ee47bd62976Mark Andrews #
e334405421979688f2d838805ac67ee47bd62976Mark Andrews echo $$ > "${PID_FILE}"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews rm -f "${LOG_FILE}"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews exec "${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
e334405421979688f2d838805ac67ee47bd62976Mark Andrews org.opends.server.core.DirectoryServer \
e334405421979688f2d838805ac67ee47bd62976Mark Andrews --configClass org.opends.server.extensions.ConfigFileHandler \
e334405421979688f2d838805ac67ee47bd62976Mark Andrews --configFile "${CONFIG_FILE}" "${@}"
e334405421979688f2d838805ac67ee47bd62976Mark Andrews else
e334405421979688f2d838805ac67ee47bd62976Mark Andrews #
e334405421979688f2d838805ac67ee47bd62976Mark Andrews # an error or the server is already started. Just return the code provided
e334405421979688f2d838805ac67ee47bd62976Mark Andrews # by checkstartability
e334405421979688f2d838805ac67ee47bd62976Mark Andrews #
e334405421979688f2d838805ac67ee47bd62976Mark Andrews exit ${EC}
e334405421979688f2d838805ac67ee47bd62976Mark Andrews fi
b8a9a7bef2c3060204c68aef4f3fce04afc1aaeeAutomatic Updaterfi
e334405421979688f2d838805ac67ee47bd62976Mark Andrews