start-ds revision 3488
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#!/bin/sh
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# CDDL HEADER START
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# The contents of this file are subject to the terms of the
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# Common Development and Distribution License, Version 1.0 only
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# (the "License"). You may not use this file except in compliance
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# with the License.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# You can obtain a copy of the license at
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# trunk/opends/resource/legal-notices/OpenDS.LICENSE
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# See the License for the specific language governing permissions
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# and limitations under the License.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# When distributing Covered Code, include this CDDL HEADER in each
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# file and include the License file at
b7e0eb2a569767e809950d95f945ebf4bdcd9bf6Laszlo Hordos# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# add the following below this CDDL HEADER, with the fields enclosed
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# by brackets "[]" replaced with your own identifying information:
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# Portions Copyright [yyyy] [name of copyright owner]
95a1999c80b3861230dabc65b91d0b802a3b62f0Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# CDDL HEADER END
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# Copyright 2006-2008 Sun Microsystems, Inc.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# Capture the current working directory so that we can change to it later.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# Then capture the location of this script and the Directory Server instance
29b501990ace032d7b959ac1afd1ec75533e8baePaul Bryan# root so that we can use them to create appropriate paths.
aa26d20912b59f80d1b06b9c0a34c2d4de507a4fLaszlo HordosWORKING_DIR=`pwd`
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos
6007d9c03a5f58ab1aaa7679709d1c47d0e61040Andi Egloffcd "`dirname "${0}"`"
6007d9c03a5f58ab1aaa7679709d1c47d0e61040Andi EgloffSCRIPT_DIR=`pwd`
6007d9c03a5f58ab1aaa7679709d1c47d0e61040Andi Egloff
6007d9c03a5f58ab1aaa7679709d1c47d0e61040Andi Egloffcd ..
6007d9c03a5f58ab1aaa7679709d1c47d0e61040Andi EgloffINSTANCE_ROOT=`pwd`
43689602ee8a67deb29ea8412c48410dcaa6b30aLaszlo Hordosexport INSTANCE_ROOT
43689602ee8a67deb29ea8412c48410dcaa6b30aLaszlo Hordos
43689602ee8a67deb29ea8412c48410dcaa6b30aLaszlo Hordoscd "${WORKING_DIR}"
43689602ee8a67deb29ea8412c48410dcaa6b30aLaszlo Hordos
43689602ee8a67deb29ea8412c48410dcaa6b30aLaszlo Hordos# Specify the locations of important files that may be used when the server
87723f2895f37176408ecb9037bb77388cc5a008Andi Egloff# is starting.
87723f2895f37176408ecb9037bb77388cc5a008Andi EgloffCONFIG_FILE=${INSTANCE_ROOT}/config/config.ldif
29b501990ace032d7b959ac1afd1ec75533e8baePaul BryanPID_FILE=${INSTANCE_ROOT}/logs/server.pid
aa26d20912b59f80d1b06b9c0a34c2d4de507a4fLaszlo HordosLOG_FILE=${INSTANCE_ROOT}/logs/server.out
87723f2895f37176408ecb9037bb77388cc5a008Andi EgloffSTARTING_FILE=${INSTANCE_ROOT}/logs/server.starting
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan
10a9be648c010204b8ba63b283aa177749227e11Paul Bryan# Specify the script name so that it may be provided in command-line usage.
10a9be648c010204b8ba63b283aa177749227e11Paul BryanSCRIPT_NAME="start-ds"
10a9be648c010204b8ba63b283aa177749227e11Paul Bryanexport SCRIPT_NAME
5fc4ae486aef7fabd30ff1d12e8324ca9077b394Andi Egloff
5fc4ae486aef7fabd30ff1d12e8324ca9077b394Andi Egloff# Set environment variables
5fc4ae486aef7fabd30ff1d12e8324ca9077b394Andi EgloffSCRIPT_UTIL_CMD=set-full-environment-and-test-java
5fc4ae486aef7fabd30ff1d12e8324ca9077b394Andi Egloffexport SCRIPT_UTIL_CMD
5fc4ae486aef7fabd30ff1d12e8324ca9077b394Andi Egloff. "${INSTANCE_ROOT}/lib/_script-util.sh"
5fc4ae486aef7fabd30ff1d12e8324ca9077b394Andi EgloffRETURN_CODE=$?
11584e05cc53d957ed964dfba41dd3d716f28480Gael Alliouxif test ${RETURN_CODE} -ne 0
11584e05cc53d957ed964dfba41dd3d716f28480Gael Alliouxthen
11584e05cc53d957ed964dfba41dd3d716f28480Gael Allioux exit ${RETURN_CODE}
11584e05cc53d957ed964dfba41dd3d716f28480Gael Alliouxfi
11584e05cc53d957ed964dfba41dd3d716f28480Gael Allioux
11584e05cc53d957ed964dfba41dd3d716f28480Gael Allioux
116744be25a66af50d81a0ab68ddce40be7bfcf8Andi Egloff# See if the provided set of arguments were sufficient for us to be able to
116744be25a66af50d81a0ab68ddce40be7bfcf8Andi Egloff# start the server or perform the requested operation. An exit code of 99
116744be25a66af50d81a0ab68ddce40be7bfcf8Andi Egloff# means that it should be possible to start the server. An exit code of 98
116744be25a66af50d81a0ab68ddce40be7bfcf8Andi Egloff# means that the server is already running and we shouldn't try to start it.
116744be25a66af50d81a0ab68ddce40be7bfcf8Andi Egloff# An exit code of anything else means that we're not trying to start the server
55bb82d605d054ef979dfd6c70325ad5f9936ad3Andi Egloff# and we can just exit with that exit code.
55bb82d605d054ef979dfd6c70325ad5f9936ad3Andi Egloff${OPENDS_JAVA_BIN} ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
55bb82d605d054ef979dfd6c70325ad5f9936ad3Andi Egloff --configClass org.opends.server.extensions.ConfigFileHandler \
55bb82d605d054ef979dfd6c70325ad5f9936ad3Andi Egloff --configFile "${CONFIG_FILE}" --checkStartability "${@}"
55bb82d605d054ef979dfd6c70325ad5f9936ad3Andi EgloffEC=${?}
dedea1c74ef770604ee181088cedc7bd891486baAndi Egloffif test ${EC} -eq 99 -o ${EC} -eq 103
dedea1c74ef770604ee181088cedc7bd891486baAndi Egloffthen
dedea1c74ef770604ee181088cedc7bd891486baAndi Egloff #
dedea1c74ef770604ee181088cedc7bd891486baAndi Egloff # run detach
dedea1c74ef770604ee181088cedc7bd891486baAndi Egloff #
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos touch "${STARTING_FILE}"
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos nohup "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos org.opends.server.core.DirectoryServer \
aa26d20912b59f80d1b06b9c0a34c2d4de507a4fLaszlo Hordos --configClass org.opends.server.extensions.ConfigFileHandler \
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos --configFile "${CONFIG_FILE}" "${@}" > "${LOG_FILE}" 2>&1 &
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos echo $! > "${PID_FILE}"
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos if test ${EC} -eq 99
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos then
aa26d20912b59f80d1b06b9c0a34c2d4de507a4fLaszlo Hordos "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos --targetFile "${STARTING_FILE}" --logFile "${LOG_FILE}"
7586bb16914a8a62557e2e56c74a637a451fdd4eAndi Egloff else
7586bb16914a8a62557e2e56c74a637a451fdd4eAndi Egloff "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
29b501990ace032d7b959ac1afd1ec75533e8baePaul Bryan --targetFile "${STARTING_FILE}"
aa26d20912b59f80d1b06b9c0a34c2d4de507a4fLaszlo Hordos fi
7586bb16914a8a62557e2e56c74a637a451fdd4eAndi Egloff EC=${?}
f17bd17365d88d445f029b5859bf524ede9a92f0Andi Egloff if test ${EC} -eq 0
f17bd17365d88d445f029b5859bf524ede9a92f0Andi Egloff then
f17bd17365d88d445f029b5859bf524ede9a92f0Andi Egloff # An exit code of 98 means that the server is already running.
f17bd17365d88d445f029b5859bf524ede9a92f0Andi Egloff ${OPENDS_JAVA_BIN} ${SCRIPT_NAME_ARG} org.opends.server.core.DirectoryServer \
f17bd17365d88d445f029b5859bf524ede9a92f0Andi Egloff --configClass org.opends.server.extensions.ConfigFileHandler \
bdf1b2b1491da535d3c50421c77fc8b1255e5f0aAndi Egloff --configFile "${CONFIG_FILE}" --checkStartability > /dev/null 2>&1
bdf1b2b1491da535d3c50421c77fc8b1255e5f0aAndi Egloff EC=${?}
29b501990ace032d7b959ac1afd1ec75533e8baePaul Bryan if test ${EC} -eq 98
aa26d20912b59f80d1b06b9c0a34c2d4de507a4fLaszlo Hordos then
ae79bf818de74e667aa5484483357212e418a68cJamie Nelson exit 0
ae79bf818de74e667aa5484483357212e418a68cJamie Nelson else
ae79bf818de74e667aa5484483357212e418a68cJamie Nelson # Could not start the server
ae79bf818de74e667aa5484483357212e418a68cJamie Nelson exit 1
ae79bf818de74e667aa5484483357212e418a68cJamie Nelson fi
bdf1b2b1491da535d3c50421c77fc8b1255e5f0aAndi Egloff fi
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos exit ${?}
29b501990ace032d7b959ac1afd1ec75533e8baePaul Bryanelse
29b501990ace032d7b959ac1afd1ec75533e8baePaul Bryan if test ${EC} -eq 100
aa26d20912b59f80d1b06b9c0a34c2d4de507a4fLaszlo Hordos then
0fdda69ce3627d501e4bb3103765f676bb1ab061Laszlo Hordos #
b7e0eb2a569767e809950d95f945ebf4bdcd9bf6Laszlo Hordos # run no detach
1e74f7af8c740d5ac7ea678c3f0f53457629449dAndi Egloff #
1e74f7af8c740d5ac7ea678c3f0f53457629449dAndi Egloff echo $$ > "${PID_FILE}"
1e74f7af8c740d5ac7ea678c3f0f53457629449dAndi Egloff rm -f "${LOG_FILE}"
1e74f7af8c740d5ac7ea678c3f0f53457629449dAndi Egloff exec "${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
d8c8adcd3b632462e4ae3332e81208d29ea09ce2Laszlo Hordos org.opends.server.core.DirectoryServer \
d8c8adcd3b632462e4ae3332e81208d29ea09ce2Laszlo Hordos --configClass org.opends.server.extensions.ConfigFileHandler \
d8c8adcd3b632462e4ae3332e81208d29ea09ce2Laszlo Hordos --configFile "${CONFIG_FILE}" "${@}"
d8c8adcd3b632462e4ae3332e81208d29ea09ce2Laszlo Hordos else
d8c8adcd3b632462e4ae3332e81208d29ea09ce2Laszlo Hordos #
dd37dcbebe120d68ca67144b7f943f0317deda38Andi Egloff # an error or the server is already started. Just return the code provided
dd37dcbebe120d68ca67144b7f943f0317deda38Andi Egloff # by checkstartability
dd37dcbebe120d68ca67144b7f943f0317deda38Andi Egloff #
dd37dcbebe120d68ca67144b7f943f0317deda38Andi Egloff exit ${EC}
dd37dcbebe120d68ca67144b7f943f0317deda38Andi Egloff fi
dd37dcbebe120d68ca67144b7f943f0317deda38Andi Eglofffi
dd37dcbebe120d68ca67144b7f943f0317deda38Andi Egloff