stop-ds revision 2296
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence# CDDL HEADER START
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# The contents of this file are subject to the terms of the
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# Common Development and Distribution License, Version 1.0 only
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence# (the "License"). You may not use this file except in compliance
15a44745412679c30a6d022733925af70a38b715David Lawrence# with the License.
15a44745412679c30a6d022733925af70a38b715David Lawrence# You can obtain a copy of the license at
15a44745412679c30a6d022733925af70a38b715David Lawrence# trunk/opends/resource/legal-notices/OpenDS.LICENSE
15a44745412679c30a6d022733925af70a38b715David Lawrence# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
15a44745412679c30a6d022733925af70a38b715David Lawrence# See the License for the specific language governing permissions
15a44745412679c30a6d022733925af70a38b715David Lawrence# and limitations under the License.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# When distributing Covered Code, include this CDDL HEADER in each
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# file and include the License file at
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# add the following below this CDDL HEADER, with the fields enclosed
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# by brackets "[]" replaced with your own identifying information:
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# Portions Copyright [yyyy] [name of copyright owner]
9779deddba39f1ccc5e73e3c0d721f2253bcaccaBob Halley# CDDL HEADER END
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence# Portions Copyright 2006-2007 Sun Microsystems, Inc.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# This script may be used to request that the Directory Server shut down.
63bb6b854b6db073856b0f2b2924d1af33e0eaf6Andreas Gustafsson# It operates in two different ways, depending on how it is invoked. If it
911ed0d3bee586b3bec42cb6c376d5cc6c0e1e24Brian Wellington# is invoked without any arguments and a local PID file is available, then it
63bb6b854b6db073856b0f2b2924d1af33e0eaf6Andreas Gustafsson# will stop the server by sending a TERM signal to the process, and this
63bb6b854b6db073856b0f2b2924d1af33e0eaf6Andreas Gustafsson# script will wait until the server has stopped before exiting. If any
63bb6b854b6db073856b0f2b2924d1af33e0eaf6Andreas Gustafsson# arguments were provided or there is no local PID file, then it will attempt
63bb6b854b6db073856b0f2b2924d1af33e0eaf6Andreas Gustafsson# to stop the server using an LDAP request.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# Capture the current working directory so that we can change to it later.
63bb6b854b6db073856b0f2b2924d1af33e0eaf6Andreas Gustafsson# Then capture the location of this script and the Directory Server instance
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# root so that we can use them to create appropriate paths.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssoncd "${WORKING_DIR}"
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence# See if JAVA_HOME is set. If not, then see if there is a java executable in
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence# the path and try to figure it out.
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrenceif test -z "${JAVA_BIN}"
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence if test -z "${JAVA_HOME}"
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence if test -f "${INSTANCE_ROOT}/lib/set-java-home"
f2fdfe7c42f3b10f3653f851ce5a0a90ee5ac1f9David Lawrence . "${INSTANCE_ROOT}/lib/set-java-home"
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# system environment variables for security and compatibility reasons.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
9d34fb782676f3cc5fccc2e50468549934110f1cAndreas Gustafsson# Configure the appropriate CLASSPATH.
35b22d104a60d8f2305100e00ae0d6cb5efe1722Andreas Gustafsson# Specify the script name so that it may be provided in command-line usage.
35b22d104a60d8f2305100e00ae0d6cb5efe1722Andreas GustafssonSCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=stop-ds"
35b22d104a60d8f2305100e00ae0d6cb5efe1722Andreas Gustafsson# Test that the provided JDK is 1.5 compatible.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonif test -z "${JAVA_ARGS}"
0d32cdd9a07819b03f2b07fc8fdcdb0a227eee0bMark Andrews "${JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson echo "ERROR: The detected Java version could not be used. Please set "
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson echo " JAVA_HOME to the root of a Java 5.0 installation."
80afc68f7784868d68f544df4be0e9f9711323a5Andreas Gustafsson "${JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
4b887af61910a8d7ed1d2d013d956f56e54c0e23Andreas Gustafsson echo "ERROR: The detected Java version could not be used with the specified"
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson echo "Java arguments. Please set JAVA_HOME to the root of a Java 5.0 installation."
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson"${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson org.opends.server.tools.StopDS --checkStoppability "${@}"
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# Already stopped and nothing else to do.
0f78de4d61441acbb0af7088c2dfda60a7ed5500Brian Wellington # Already stopped and must start locally.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence # Stop using system call
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson # Restart using system call
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonif test ${MUST_STOP_USING_SYSTEM_CALL} -eq 0
4b887af61910a8d7ed1d2d013d956f56e54c0e23Andreas Gustafsson if test -f "${INSTANCE_ROOT}/logs/server.pid"
897ba5e12014b2001dba9ef7fceeec7d9182e447Andreas Gustafsson kill `cat "${INSTANCE_ROOT}/logs/server.pid"`
897ba5e12014b2001dba9ef7fceeec7d9182e447Andreas Gustafsson "${JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson echo "ERROR: Unable to find the server.pid file to determine the process"
897ba5e12014b2001dba9ef7fceeec7d9182e447Andreas Gustafsson echo " ID of the OpenDS process to terminate."
897ba5e12014b2001dba9ef7fceeec7d9182e447Andreas Gustafsson# Delete the pid file if the server is stopped (this can occur if the process
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# has been killed using kill -9).
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if test -f "${INSTANCE_ROOT}/logs/server.pid"
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson# Now if the user wants to restart the server, try to restart it if the server
63bb6b854b6db073856b0f2b2924d1af33e0eaf6Andreas Gustafsson "${INSTANCE_ROOT}/bin/start-ds"
80afc68f7784868d68f544df4be0e9f9711323a5Andreas Gustafsson# The user does not want to start the server locally and it is already stopped.
d60f5b9bc8c1e1f7ddebc6c7834f7550a8e8be6fBob Halley# If we've gotten here, then we should try to stop the server over LDAP.