start-ds revision 6983
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 legal-notices/CDDLv1_0.txt
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# or http://forgerock.org/license/CDDLv1.0.html.
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 legal-notices/CDDLv1_0.txt.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# If applicable, add the following below this CDDL HEADER, with the
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# fields enclosed by brackets "[]" replaced with your own identifying
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# information:
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Portions Copyright [yyyy] [name of copyright owner]
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# CDDL HEADER END
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Copyright 2006-2009 Sun Microsystems, Inc.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Portions Copyright 2011-2013 ForgeRock AS
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Capture the current working directory so that we can change to it later.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Then capture the location of this script and the Directory Server instance
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# root so that we can use them to create appropriate paths.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeWORKING_DIR=`pwd`
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipecd "`dirname "${0}"`"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeSCRIPT_DIR=`pwd`
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipecd ..
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeINSTALL_ROOT=`pwd`
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeexport INSTALL_ROOT
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipecd "${WORKING_DIR}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Specify the script name so that it may be provided in command-line usage.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeSCRIPT_NAME="start-ds"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeexport SCRIPT_NAME
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# check for presence of lib/_svc-opendj.sh file
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# If present, we should be on Solaris/OpenSolaris and use SMF to start
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# OpenDJ.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Check --exec. If not present, start OpenDJ from SMF
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeif test -f "${INSTALL_ROOT}/lib/_svc-opendj.sh"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipethen
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe if [ "$1" = "--exec" ]
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe shift
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe elif [ -z "$1" -o "$1" = "-L" -o "$1" = "-Q" -o "$1" = "-N" -o \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe "$1" = "--nodetach" -o "$1" = "-useLastKnownGoodConfig" \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe -o "$1" = "--quiet" ]
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# these options are only used when trying to start the server
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# In this case, start it through the service.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe exec /usr/sbin/svcadm enable -t svc:/network/ldap/server:opendj
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipefi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Set environment variables
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeSCRIPT_UTIL_CMD=set-full-environment-and-test-java
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeexport SCRIPT_UTIL_CMD
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe. "${INSTALL_ROOT}/lib/_script-util.sh"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeRETURN_CODE=$?
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeif test ${RETURN_CODE} -ne 0
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipethen
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe exit ${RETURN_CODE}
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipefi
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
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# See if the provided set of arguments were sufficient for us to be able to
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# start the server or perform the requested operation. An exit code of 99
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# means that it should be possible to start the server. An exit code of 98
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# means that the server is already running and we shouldn't try to start it.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# An exit code of anything else means that we're not trying to start the server
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# and we can just exit with that exit code.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe"${OPENDJ_JAVA_BIN}" -client ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe --configClass org.opends.server.extensions.ConfigFileHandler \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe --configFile "${CONFIG_FILE}" --checkStartability "${@}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeEC=${?}
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeif test ${EC} -eq 99 -o ${EC} -eq 103
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipethen
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe #
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe # run detach
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe #
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe touch "${STARTING_FILE}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe nohup "${OPENDJ_JAVA_BIN}" ${OPENDJ_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 if test ${EC} -eq 99
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe --targetFile "${STARTING_FILE}" --logFile "${LOG_FILE}" "${@}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe else
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe --targetFile "${STARTING_FILE}" "${@}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe EC=${?}
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe if test ${EC} -eq 0
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
# An exit code of 98 means that the server is already running.
"${OPENDJ_JAVA_BIN}" -client ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
--configClass org.opends.server.extensions.ConfigFileHandler \
--configFile "${CONFIG_FILE}" --checkStartability > /dev/null 2>&1
EC=${?}
if test ${EC} -eq 98
then
exit 0
else
# Could not start the server
exit 1
fi
fi
exit ${EC}
else
if test ${EC} -eq 100
then
#
# run no detach
#
echo $$ > "${PID_FILE}"
rm -f "${LOG_FILE}"
exec "${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
org.opends.server.core.DirectoryServer \
--configClass org.opends.server.extensions.ConfigFileHandler \
--configFile "${CONFIG_FILE}" "${@}"
elif test ${EC} -eq 104
then
#
# run no detach quiet
#
echo $$ > "${PID_FILE}"
rm -f "${LOG_FILE}"
exec "${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
org.opends.server.core.DirectoryServer \
--configClass org.opends.server.extensions.ConfigFileHandler \
--configFile "${CONFIG_FILE}" "${@}" > /dev/null
else
#
# an error or the server is already started. Just return the code provided
# by checkstartability
#
exit ${EC}
fi
fi