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