stop-ds revision d319724fed3be916a9f68676aac6eb203d44b551
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# CDDL HEADER START
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# The contents of this file are subject to the terms of the
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Common Development and Distribution License, Version 1.0 only
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# (the "License"). You may not use this file except in compliance
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# with the License.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# You can obtain a copy of the license at
4f2de35716c5df46152747980516af484d0ab208Adam Moore# trunk/opends/resource/legal-notices/OpenDS.LICENSE
02fc09f797e83e80199c96adc4751c230dccc973Adam Moore# See the License for the specific language governing permissions
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# and limitations under the License.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# When distributing Covered Code, include this CDDL HEADER in each
5f8408be995d28c8f351f37fd05e7c8633fdea40Adam Moore# file and include the License file at
5f8408be995d28c8f351f37fd05e7c8633fdea40Adam Moore# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
5f8408be995d28c8f351f37fd05e7c8633fdea40Adam Moore# add the following below this CDDL HEADER, with the fields enclosed
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# by brackets "[]" replaced with your own identifying information:
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Portions Copyright [yyyy] [name of copyright owner]
c4f19796d319a7ec9a1e76d48adc82c9c5ae2f27Adam Moore# CDDL HEADER END
0dca577a07715960da42d47787eecc25b285182fAdam Moore# Copyright 2006-2008 Sun Microsystems, Inc.
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# This script may be used to request that the Directory Server shut down.
f647f9c7909e84a0b19f09de42ce82a715e2d52aAdam Moore# It operates in two different ways, depending on how it is invoked. If it
0771d781138a507b3e657573703f511291640bf3Adam Moore# is invoked without any arguments and a local PID file is available, then it
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# will stop the server by sending a TERM signal to the process, and this
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# script will wait until the server has stopped before exiting. If any
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# arguments were provided or there is no local PID file, then it will attempt
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# to stop the server using an LDAP request.
9cdb1aa8d3a7901f789c2ad7a6ea00e804a9abebAdam Moore# Capture the current working directory so that we can change to it later.
0771d781138a507b3e657573703f511291640bf3Adam Moore# Then capture the location of this script and the Directory Server instance
0771d781138a507b3e657573703f511291640bf3Adam Moore# root so that we can use them to create appropriate paths.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moorecd "${WORKING_DIR}"
8aa0880cd494c951e0f4aa7d82d8bdac7692c7d0Adam Moore# We keep this values to reset the environment before calling start-ds.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Specify the script name so that we can use the specified java properties.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Set environment variables
80d2034f65b9348e5fd36291f03b0819181efb89Adam MooreSCRIPT_UTIL_CMD=set-full-environment-and-test-java
fb49666327c2cb6ea5a7d2dea5160b649bc07c51Adam Moore. "${INSTALL_ROOT}/lib/_script-util.sh"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore org.opends.server.tools.StopDS --checkStoppability "${@}"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Already stopped and nothing else to do.
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore # Already stopped and must start locally.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore # Stop using system call
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore # Restart using system call
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test -f "${INSTANCE_ROOT}/logs/server.pid"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore echo "ERROR: Unable to find the server.pid file to determine the process"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore echo " ID of the OpenDS process to terminate."
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Delete the pid file if the server is stopped (this can occur if the process
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# has been killed using kill -9).
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test -f "${INSTANCE_ROOT}/logs/server.pid"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Now if the user wants to restart the server, try to restart it if the server
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore# is stopped.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Set the original values that the user had on the environment in order to be
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# sure that the start-ds script works with the proper arguments (in particular
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# if the user specified not to overwrite the environment).
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore "${INSTALL_ROOT}/bin/start-ds"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# The user does not want to start the server locally and it is already stopped.
9bc9c1474a84983bd254adc2bc425c5b24d25526Adam Moore# If we've gotten here, then we should try to stop the server over LDAP.
9bc9c1474a84983bd254adc2bc425c5b24d25526Adam Moore"${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \