stop-ds revision 1181
63f0e65a37b95621334db9ee4ba0cd9d826f5c0fChristian Maeder# CDDL HEADER START
5191fa24c532d1f67e7a642e9aece65efb8a0975Christian Maeder# The contents of this file are subject to the terms of the
43b4c41fbb07705c9df321221ab9cb9832460407Christian Maeder# Common Development and Distribution License, Version 1.0 only
5191fa24c532d1f67e7a642e9aece65efb8a0975Christian Maeder# (the "License"). You may not use this file except in compliance
5191fa24c532d1f67e7a642e9aece65efb8a0975Christian Maeder# with the License.
43b4c41fbb07705c9df321221ab9cb9832460407Christian Maeder# You can obtain a copy of the license at
5191fa24c532d1f67e7a642e9aece65efb8a0975Christian Maeder# trunk/opends/resource/legal-notices/OpenDS.LICENSE
f4a2a20e49f41b2afa657e5e64d9e349c7faa091Christian Maeder# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
f2f9df2e17e70674f0bf426ed1763c973ee4cde0Christian Maeder# See the License for the specific language governing permissions
5191fa24c532d1f67e7a642e9aece65efb8a0975Christian Maeder# and limitations under the License.
5191fa24c532d1f67e7a642e9aece65efb8a0975Christian Maeder# When distributing Covered Code, include this CDDL HEADER in each
68d10d143f29fcff3c637ba24f90e983995ceae6Christian Maeder# file and include the License file at
a53841f6d6e86ac751c12a33dc8aadf53f59d977Klaus Luettich# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
a53841f6d6e86ac751c12a33dc8aadf53f59d977Klaus Luettich# add the following below this CDDL HEADER, with the fields enclosed
a53841f6d6e86ac751c12a33dc8aadf53f59d977Klaus Luettich# by brackets "[]" replaced with your own identifying information:
a53841f6d6e86ac751c12a33dc8aadf53f59d977Klaus Luettich# Portions Copyright [yyyy] [name of copyright owner]
68d10d143f29fcff3c637ba24f90e983995ceae6Christian Maeder# CDDL HEADER END
3b06e23643a9f65390cb8c1caabe83fa7e87a708Till Mossakowski# Portions Copyright 2006-2007 Sun Microsystems, Inc.
ce8b15da31cd181b7e90593cbbca98f47eda29d6Till Mossakowski# This script may be used to request that the Directory Server shut down.
e7757995211bd395dc79d26fe017d99375f7d2a6Christian Maeder# It operates in two different ways, depending on how it is invoked. If it
e7757995211bd395dc79d26fe017d99375f7d2a6Christian Maeder# is invoked without any arguments and a local PID file is available, then it
63f0e65a37b95621334db9ee4ba0cd9d826f5c0fChristian Maeder# will stop the server by sending a TERM signal to the process, and this
63f0e65a37b95621334db9ee4ba0cd9d826f5c0fChristian Maeder# script will wait until the server has stopped before exiting. If any
a1ed34933c266ce85066acb0d7b20c90cb8eb213Christian Maeder# arguments were provided or there is no local PID file, then it will attempt
c0c2380bced8159ff0297ece14eba948bd236471Christian Maeder# to stop the server using an LDAP request.
63f0e65a37b95621334db9ee4ba0cd9d826f5c0fChristian Maeder# Capture the current working directory so that we can change to it later.
8410667510a76409aca9bb24ff0eda0420088274Christian Maeder# Then capture the location of this script and the Directory Server instance
404166b9366552e9ec5abb87a37c76ec8a815fb7Klaus Luettich# root so that we can use them to create appropriate paths.
55adfe57a4de1f36adc3e3bfc16f342e44a7d444Christian Maedercd "${WORKING_DIR}"
f4a2a20e49f41b2afa657e5e64d9e349c7faa091Christian Maeder# See if JAVA_HOME is set. If not, then see if there is a java executable in
63f0e65a37b95621334db9ee4ba0cd9d826f5c0fChristian Maeder# the path and try to figure it out.
e593b89bfd4952698dc37feced21cefe869d87a2Christian Maederif test -z "${JAVA_BIN}"
5191fa24c532d1f67e7a642e9aece65efb8a0975Christian Maeder if test -z "${JAVA_HOME}"
1aee4aaddde105264c1faf394d88e302c05094ffChristian Maeder if test -f "${INSTANCE_ROOT}/bin/set-java-home"
f041c9a6bda23de33a38490e35b831ae18d96b45Christian Maeder . "${INSTANCE_ROOT}/bin/set-java-home"
2c9df69accd8924e7cef3bf8f686626958499c7aChristian Maeder echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
79e80c4b3f0ebb337d84415a50f29ccfc793e68bChristian Maeder# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
79e80c4b3f0ebb337d84415a50f29ccfc793e68bChristian Maeder# system environment variables for security and compatibility reasons.
363939beade943a02b31004cea09dec34fa8a6d9Christian Maederexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
f04e8f3ff56405901be968fd4c6e9769239f1a9bKlaus Luettich# Configure the appropriate CLASSPATH.
9e748851c150e1022fb952bab3315e869aaf0214Christian Maeder# Specify the script name so that it may be provided in command-line usage.
9e748851c150e1022fb952bab3315e869aaf0214Christian MaederSCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=stop-ds"
6a79849bed67264c396dddb3e9c184bdfc1a1bc9Christian Maeder# Test that the provided JDK is 1.5 compatible.
6a79849bed67264c396dddb3e9c184bdfc1a1bc9Christian Maederif test -z "${JAVA_ARGS}"
a6db617ca58eb6a0587b6366e913107dfecb71b5Heng Jiang "${JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
9e748851c150e1022fb952bab3315e869aaf0214Christian Maeder echo "ERROR: The detected Java version could not be used. Please set "
9e748851c150e1022fb952bab3315e869aaf0214Christian Maeder echo " JAVA_HOME to the root of a Java 5.0 installation."
6dc9bc98d0854fe2e3dd3bfc4275096a0c28ee1cChristian Maeder "${JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
63f0e65a37b95621334db9ee4ba0cd9d826f5c0fChristian Maeder echo "ERROR: The detected Java version could not be used with the specified"
61fa0ac06ede811c7aad54ec4c4202346727368eChristian Maeder echo "Java arguments. Please set JAVA_HOME to the root of a Java 5.0 installation."
63f0e65a37b95621334db9ee4ba0cd9d826f5c0fChristian Maeder"${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
63f0e65a37b95621334db9ee4ba0cd9d826f5c0fChristian Maeder org.opends.server.tools.StopDS --checkStoppability "${@}"
a5e5b8c3e5c11177e5034ef2423813a5d28979edChristian Maeder# Already stopped and nothing else to do.
bc8cbf12aa172bf5673b92a9e7a0151d4aa4c315Christian Maeder # Already stopped and must start locally.
6a79849bed67264c396dddb3e9c184bdfc1a1bc9Christian Maeder # Stop using system call
88318aafc287e92931dceffbb943d58a9310001dChristian Maeder # Restart using system call
4017ebc0f692820736d796af3110c3b3018c108aChristian Maederif test ${MUST_STOP_USING_SYSTEM_CALL} -eq 0
ca074a78b8dcccbb8c419586787882f98d0c6163Christian Maeder if test -f "${INSTANCE_ROOT}/logs/server.pid"
ca074a78b8dcccbb8c419586787882f98d0c6163Christian Maeder kill `cat "${INSTANCE_ROOT}/logs/server.pid"`
f2f9df2e17e70674f0bf426ed1763c973ee4cde0Christian Maeder "${JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
d946c1bfdd7d58aa7c023efe864d5999eb44a61bChristian Maeder --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
63f0e65a37b95621334db9ee4ba0cd9d826f5c0fChristian Maeder# Delete the pid file if the server is stopped (this can occur if the process
63f0e65a37b95621334db9ee4ba0cd9d826f5c0fChristian Maeder# has been killed using kill -9).
d23b0cc79c0d204e6ec758dff8d0ba71c9f693f7Christian Maeder if test -f "${INSTANCE_ROOT}/logs/server.pid"
363939beade943a02b31004cea09dec34fa8a6d9Christian Maeder# Now if the user wants to restart the server, try to restart it if the server
f1541d4a151dbd08002dbd14e7eb1d5dde253689Christian Maederif test ${MUST_START_USING_SYSTEM_CALL} -eq 0
5191fa24c532d1f67e7a642e9aece65efb8a0975Christian Maeder "${INSTANCE_ROOT}/bin/start-ds"
5191fa24c532d1f67e7a642e9aece65efb8a0975Christian Maeder# The user does not want to start the server locally and it is already stopped.
6a79849bed67264c396dddb3e9c184bdfc1a1bc9Christian Maeder# If we've gotten here, then we should try to stop the server over LDAP.
63f0e65a37b95621334db9ee4ba0cd9d826f5c0fChristian Maeder"${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \