stop-ds revision 7070667c2dffad87009999bdeb16d5305e0afdbe
9c49c394b4218cc9c743a372a8fcfb787f5ea8caAndreas Gustafsson# CDDL HEADER START
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# The contents of this file are subject to the terms of the
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Common Development and Distribution License, Version 1.0 only
9c49c394b4218cc9c743a372a8fcfb787f5ea8caAndreas Gustafsson# (the "License"). You may not use this file except in compliance
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox User# with the License.
83a28ca274521e15086fc39febde507bcc4e145eMark Andrews# You can obtain a copy of the license at
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt# trunk/opends/resource/legal-notices/OpenDS.LICENSE
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt# See the License for the specific language governing permissions
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# and limitations under the License.
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt# When distributing Covered Code, include this CDDL HEADER in each
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# file and include the License file at
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# add the following below this CDDL HEADER, with the fields enclosed
072440df4f65033eb058c06f2cc72be450606720Jeremy Reed# by brackets "[]" replaced with your own identifying information:
a8f6b2aa46f882c7c680b7bdab1dfb78a76787eaMark Andrews# Portions Copyright [yyyy] [name of copyright owner]
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# CDDL HEADER END
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Portions Copyright 2006-2007 Sun Microsystems, Inc.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# This script may be used to request that the Directory Server shut down.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# It operates in two different ways, depending on how it is invoked. If it
704e6c8876907aac0bf7380effca8bca400d4acdMark Andrews# is invoked without any arguments and a local PID file is available, then it
704e6c8876907aac0bf7380effca8bca400d4acdMark Andrews# will stop the server by sending a TERM signal to the process, and this
704e6c8876907aac0bf7380effca8bca400d4acdMark Andrews# script will wait until the server has stopped before exiting. If any
704e6c8876907aac0bf7380effca8bca400d4acdMark Andrews# arguments were provided or there is no local PID file, then it will attempt
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# to stop the server using an LDAP request.
c1a883f2e04d94e99c433b1f6cfd0c0338f4ed85Mark Andrews# Capture the current working directory so that we can change to it later.
030aac3dbc57f99bad1d251b0783890ff0369952Automatic Updater# Then capture the location of this script and the Directory Server instance
d60212e03fbef1d3dd7f7eb05c0545cc373cb9fcAutomatic Updater# root so that we can use them to create appropriate paths.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeincd "${WORKING_DIR}"
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt# See if JAVA_HOME is set. If not, then see if there is a java executable in
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# the path and try to figure it out.
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Huntif test -z "${JAVA_BIN}"
e02fa56849131911e9554133b17a5325b37d0828Michał Kępień if test -z "${JAVA_HOME}"
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt if test -f "${INSTANCE_ROOT}/bin/set-java-home"
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt . "${INSTANCE_ROOT}/bin/set-java-home"
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
8f7de3db7ec299ddeded142905f5eb1f22076353Evan Hunt# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# system environment variables for security and compatibility reasons.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Configure the appropriate CLASSPATH.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Specify the script name so that it may be provided in command-line usage.
b98225ff8a5721a998ccb440df4d261488fef163Mark AndrewsSCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=stop-ds"
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt org.opends.server.tools.StopDS --checkStoppability "${@}"
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt# Already stopped and nothing else to do.
b98225ff8a5721a998ccb440df4d261488fef163Mark Andrews # Already stopped and must start locally.
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt # Stop using system call
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt # Restart using system call
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt if test -f "${INSTANCE_ROOT}/logs/server.pid"
e02fa56849131911e9554133b17a5325b37d0828Michał Kępień "${JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
e02fa56849131911e9554133b17a5325b37d0828Michał Kępień --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt# Delete the pid file if the server is stopped (this can occur if the process
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt# has been killed using kill -9).
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt if test -f "${INSTANCE_ROOT}/logs/server.pid"
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt# Now if the user wants to restart the server, try to restart it if the server
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt# is stopped.
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt "${INSTANCE_ROOT}/bin/start-ds"
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt# The user does not want to start the server locally and it is already stopped.
ca6e60cb704c4c8eea1385a9fbef3eaa476eca28Evan Hunt# If we've gotten here, then we should try to stop the server over LDAP.