start-ds revision 5306
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley#!/bin/sh
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley#
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# CDDL HEADER START
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley#
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# The contents of this file are subject to the terms of the
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# Common Development and Distribution License, Version 1.0 only
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# (the "License"). You may not use this file except in compliance
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# with the License.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley#
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# You can obtain a copy of the license at
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# trunk/opends/resource/legal-notices/OpenDS.LICENSE
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# See the License for the specific language governing permissions
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# and limitations under the License.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley#
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# When distributing Covered Code, include this CDDL HEADER in each
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# file and include the License file at
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# add the following below this CDDL HEADER, with the fields enclosed
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# by brackets "[]" replaced with your own identifying information:
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# Portions Copyright [yyyy] [name of copyright owner]
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley#
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# CDDL HEADER END
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley#
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley#
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# Copyright 2006-2009 Sun Microsystems, Inc.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# Portions Copyright 2011 ForgeRock AS
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# Capture the current working directory so that we can change to it later.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# Then capture the location of this script and the Directory Server instance
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# root so that we can use them to create appropriate paths.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleyWORKING_DIR=`pwd`
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleycd "`dirname "${0}"`"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleySCRIPT_DIR=`pwd`
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleycd ..
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleyINSTALL_ROOT=`pwd`
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleyexport INSTALL_ROOT
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleycd "${WORKING_DIR}"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# Specify the script name so that it may be provided in command-line usage.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleySCRIPT_NAME="start-ds"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleyexport SCRIPT_NAME
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# check for presence of lib/_svc-opendj.sh file
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# If present, we should be on Solaris/OpenSolaris and use SMF to start
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# OpenDJ.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# Check --exec. If not present, start OpenDJ from SMF
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleyif test -f "${INSTALL_ROOT}/lib/_svc-opendj.sh"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleythen
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley if [ "$1" = "--exec" ]
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley then
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley shift
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley elif [ -z "$1" -o "$1" = "-L" -o "$1" = "-Q" -o "$1" = "-N" -o \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley "$1" = "--nodetach" -o "$1" = "-useLastKnownGoodConfig" \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley -o "$1" = "--quiet" ]
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley then
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# these options are only used when trying to start the server
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# In this case, start it through the service.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley exec /usr/sbin/svcadm enable -t svc:/network/ldap/server:opendj
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley fi
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleyfi
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# Set environment variables
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleySCRIPT_UTIL_CMD=set-full-environment-and-test-java
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleyexport SCRIPT_UTIL_CMD
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleyCHECK_VERSION=yes
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleyexport CHECK_VERSION
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley. "${INSTALL_ROOT}/lib/_script-util.sh"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleyRETURN_CODE=$?
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleyif test ${RETURN_CODE} -ne 0
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleythen
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley exit ${RETURN_CODE}
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleyfi
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# Specify the locations of important files that may be used when the server
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# is starting.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleyCONFIG_FILE=${INSTANCE_ROOT}/config/config.ldif
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleyPID_FILE=${INSTANCE_ROOT}/logs/server.pid
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleyLOG_FILE=${INSTANCE_ROOT}/logs/server.out
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleySTARTING_FILE=${INSTANCE_ROOT}/logs/server.starting
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# See if the provided set of arguments were sufficient for us to be able to
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# start the server or perform the requested operation. An exit code of 99
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# means that it should be possible to start the server. An exit code of 98
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# means that the server is already running and we shouldn't try to start it.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# An exit code of anything else means that we're not trying to start the server
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley# and we can just exit with that exit code.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley${OPENDS_JAVA_BIN} -client ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --configClass org.opends.server.extensions.ConfigFileHandler \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --configFile "${CONFIG_FILE}" --checkStartability "${@}"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob HalleyEC=${?}
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleyif test ${EC} -eq 99 -o ${EC} -eq 103
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleythen
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley #
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley # run detach
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley #
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley touch "${STARTING_FILE}"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley nohup "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley org.opends.server.core.DirectoryServer \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --configClass org.opends.server.extensions.ConfigFileHandler \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --configFile "${CONFIG_FILE}" "${@}" > "${LOG_FILE}" 2>&1 &
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley echo $! > "${PID_FILE}"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley if test ${EC} -eq 99
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley then
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley "${OPENDS_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --targetFile "${STARTING_FILE}" --logFile "${LOG_FILE}" "${@}"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley else
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley "${OPENDS_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --targetFile "${STARTING_FILE}" "${@}"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley fi
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley EC=${?}
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley if test ${EC} -eq 0
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley then
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley # An exit code of 98 means that the server is already running.
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley ${OPENDS_JAVA_BIN} -client ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --configClass org.opends.server.extensions.ConfigFileHandler \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --configFile "${CONFIG_FILE}" --checkStartability > /dev/null 2>&1
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley EC=${?}
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley if test ${EC} -eq 98
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley then
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley exit 0
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley else
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley # Could not start the server
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley exit 1
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley fi
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley fi
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley exit ${EC}
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleyelse
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley if test ${EC} -eq 100
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley then
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley #
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley # run no detach
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley #
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley echo $$ > "${PID_FILE}"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley rm -f "${LOG_FILE}"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley exec "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley org.opends.server.core.DirectoryServer \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --configClass org.opends.server.extensions.ConfigFileHandler \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --configFile "${CONFIG_FILE}" "${@}"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley elif test ${EC} -eq 104
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley then
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley #
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley # run no detach quiet
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley #
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley echo $$ > "${PID_FILE}"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley rm -f "${LOG_FILE}"
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley exec "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley org.opends.server.core.DirectoryServer \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --configClass org.opends.server.extensions.ConfigFileHandler \
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley --configFile "${CONFIG_FILE}" "${@}" > /dev/null
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley else
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley #
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley # an error or the server is already started. Just return the code provided
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley # by checkstartability
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley #
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley exit ${EC}
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley fi
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halleyfi
6ea1b817e31b89a627e146fe69e23ea0a64c89ecBob Halley