stop-ds revision 2650
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews# CDDL HEADER START
4a14ce5ba00ab7bc55c99ffdcf59c7a4ab902721Automatic Updater# The contents of this file are subject to the terms of the
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Common Development and Distribution License, Version 1.0 only
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# (the "License"). You may not use this file except in compliance
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# with the License.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# You can obtain a copy of the license at
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# trunk/opends/resource/legal-notices/OpenDS.LICENSE
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# See the License for the specific language governing permissions
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# and limitations under the License.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# When distributing Covered Code, include this CDDL HEADER in each
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User# file and include the License file at
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# add the following below this CDDL HEADER, with the fields enclosed
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# by brackets "[]" replaced with your own identifying information:
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Portions Copyright [yyyy] [name of copyright owner]
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# CDDL HEADER END
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Portions Copyright 2006-2007 Sun Microsystems, Inc.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# This script may be used to request that the Directory Server shut down.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# It operates in two different ways, depending on how it is invoked. If it
71c66a876ecca77923638d3f94cc0783152b2f03Mark Andrews# is invoked without any arguments and a local PID file is available, then it
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# will stop the server by sending a TERM signal to the process, and this
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# script will wait until the server has stopped before exiting. If any
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# arguments were provided or there is no local PID file, then it will attempt
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# to stop the server using an LDAP request.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Capture the current working directory so that we can change to it later.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Then capture the location of this script and the Directory Server instance
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# root so that we can use them to create appropriate paths.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeincd "${WORKING_DIR}"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# See if the environment variables are set. If not, then see if there is a java
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# executable in the path and try to figure it out.
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox Userif test -z "${OPENDS_JAVA_BIN}"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if test -z "${OPENDS_JAVA_HOME}"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if test -f "${INSTANCE_ROOT}/lib/set-java-home"
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User . "${INSTANCE_ROOT}/lib/set-java-home"
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User if test -z "${JAVA_BIN}"
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User if test -z "${JAVA_HOME}"
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User echo "Please set OPENDS_JAVA_HOME to the root of a Java 5 (or later) installation."
44d0f0256fbdce130a18655023c3b06bacacbd61Automatic Updater OPENDS_JAVA_BIN="${OPENDS_JAVA_HOME}/bin/java"
4cfb5ea3a5dd28477df37004d6345992d5f41a3fTinderbox User# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# system environment variables for security and compatibility reasons.
4cfb5ea3a5dd28477df37004d6345992d5f41a3fTinderbox Userexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
507151045be68c671ffd4e2f37e17cdfa0376fc4Automatic Updater# Configure the appropriate CLASSPATH.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Specify the script name so that it may be provided in command-line usage.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob AusteinSCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=stop-ds"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Test that the provided JDK is 1.5 compatible.
71c66a876ecca77923638d3f94cc0783152b2f03Mark Andrewsif test -z "${JAVA_ARGS}"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "${OPENDS_JAVA_BIN}" org.opends.server.tools.InstallDS -t 2> /dev/null
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein echo "ERROR: The detected Java version could not be used. Please set "
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein echo " JAVA_HOME to the root of a Java 5.0 installation."
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "${OPENDS_JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.InstallDS -t 2> /dev/null
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein echo "ERROR: The detected Java version could not be used with the specified"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein echo "Java arguments. Please set OPENDS_JAVA_HOME to the root of a Java 5.0 installation."
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein"${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein org.opends.server.tools.StopDS --checkStoppability "${@}"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Already stopped and nothing else to do.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # Already stopped and must start locally.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews # Stop using system call
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews # Restart using system call
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater if test -f "${INSTANCE_ROOT}/logs/server.pid"
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater kill `cat "${INSTANCE_ROOT}/logs/server.pid"`
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
afb33f777af856f8c3382604a7a8ffdfe2b512c5Automatic Updater --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein echo "ERROR: Unable to find the server.pid file to determine the process"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein echo " ID of the OpenDS process to terminate."
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Delete the pid file if the server is stopped (this can occur if the process
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# has been killed using kill -9).
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein if test -f "${INSTANCE_ROOT}/logs/server.pid"
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Now if the user wants to restart the server, try to restart it if the server
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# is stopped.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein "${INSTANCE_ROOT}/bin/start-ds"
ceeb18e6907a10547859faa340ecad83bedae90cMark Andrews# The user does not want to start the server locally and it is already stopped.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# If we've gotten here, then we should try to stop the server over LDAP.
ceeb18e6907a10547859faa340ecad83bedae90cMark Andrews"${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \