start-ds revision 2976
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest#!/bin/sh
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest#
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# CDDL HEADER START
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest#
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# The contents of this file are subject to the terms of the
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# Common Development and Distribution License, Version 1.0 only
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# (the "License"). You may not use this file except in compliance
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# with the License.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest#
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# You can obtain a copy of the license at
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# trunk/opends/resource/legal-notices/OpenDS.LICENSE
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# See the License for the specific language governing permissions
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# and limitations under the License.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest#
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# When distributing Covered Code, include this CDDL HEADER in each
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# file and include the License file at
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# add the following below this CDDL HEADER, with the fields enclosed
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# by brackets "[]" replaced with your own identifying information:
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# Portions Copyright [yyyy] [name of copyright owner]
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest#
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# CDDL HEADER END
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest#
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest#
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# Portions Copyright 2006-2007 Sun Microsystems, Inc.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# Capture the current working directory so that we can change to it later.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# Then capture the location of this script and the Directory Server instance
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# root so that we can use them to create appropriate paths.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestWORKING_DIR=`pwd`
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestcd `dirname "${0}"`
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestSCRIPT_DIR=`pwd`
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestcd ..
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestINSTANCE_ROOT=`pwd`
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestexport INSTANCE_ROOT
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestcd "${WORKING_DIR}"
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# Specify the locations of important files that may be used when the server
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# is starting.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestCONFIG_FILE=${INSTANCE_ROOT}/config/config.ldif
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestPID_FILE=${INSTANCE_ROOT}/logs/server.pid
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestLOG_FILE=${INSTANCE_ROOT}/logs/server.out
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestSTARTING_FILE=${INSTANCE_ROOT}/logs/server.starting
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# Specify the script name so that it may be provided in command-line usage.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestSCRIPT_NAME="start-ds"
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestexport SCRIPT_NAME
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# Set environment variables
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestSCRIPT_UTIL_CMD=set-full-environment-and-test-java
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestexport SCRIPT_UTIL_CMD
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest. "${INSTANCE_ROOT}/lib/_script-util.sh"
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestRETURN_CODE=$?
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestif test ${RETURN_CODE} -ne 0
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestthen
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest exit ${RETURN_CODE}
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestfi
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# See if the provided set of arguments were sufficient for us to be able to
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# start the server or perform the requested operation. An exit code of 99
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# means that it should be possible to start the server. An exit code of 98
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# means that the server is already running and we shouldn't try to start it.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# An exit code of anything else means that we're not trying to start the server
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest# and we can just exit with that exit code.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest${OPENDS_JAVA_BIN} ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest --configClass org.opends.server.extensions.ConfigFileHandler \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest --configFile "${CONFIG_FILE}" --checkStartability "${@}"
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew ForrestEC=${?}
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestif test ${EC} -eq 99 -o ${EC} -eq 103
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestthen
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest #
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest # run detach
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest #
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest touch "${STARTING_FILE}"
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest nohup "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest org.opends.server.core.DirectoryServer \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest --configClass org.opends.server.extensions.ConfigFileHandler \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest --configFile "${CONFIG_FILE}" "${@}" > "${LOG_FILE}" 2>&1 &
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest echo $! > "${PID_FILE}"
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest if test ${EC} -eq 99
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest then
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest --targetFile "${STARTING_FILE}" --logFile "${LOG_FILE}"
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest else
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest --targetFile "${STARTING_FILE}"
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest fi
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest EC=${?}
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest if test ${EC} -eq 0
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest then
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest # An exit code of 98 means that the server is already running.
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest ${OPENDS_JAVA_BIN} ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest --configClass org.opends.server.extensions.ConfigFileHandler \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest --configFile "${CONFIG_FILE}" --checkStartability > /dev/null 2>&1
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest EC=${?}
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest if test ${EC} -eq 98
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest then
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest exit 0
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest else
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest # Could not start the server
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest exit 1
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest fi
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest fi
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest exit ${?}
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestelse
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest if test ${EC} -eq 100
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest then
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest #
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest # run no detach
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest #
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest echo $$ > "${PID_FILE}"
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest rm -f "${LOG_FILE}"
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest exec "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest org.opends.server.core.DirectoryServer \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest --configClass org.opends.server.extensions.ConfigFileHandler \
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest --configFile "${CONFIG_FILE}" "${@}"
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest else
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest #
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest # an error or the server is already started. Just return the code provided
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest # by checkstartability
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest #
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest exit ${EC}
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest fi
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrestfi
ea65b6bac936db133a660beef9d75f044dd7ce84Andrew Forrest