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