stop-ds revision a3d3ab94806056d2355afea6fe8daac41059b9fb
c15b536ddbea458a7a3975079276bf4a9b1617aaMark Andrews# CDDL HEADER START
99425bedc4dcd586f751148bbdcba19578c6f39eMark Andrews# The contents of this file are subject to the terms of the
8013077aa7ed5d6e1daddc973ddb3c7cc7d28df1Mark Andrews# Common Development and Distribution License, Version 1.0 only
8013077aa7ed5d6e1daddc973ddb3c7cc7d28df1Mark Andrews# (the "License"). You may not use this file except in compliance
8013077aa7ed5d6e1daddc973ddb3c7cc7d28df1Mark Andrews# with the License.
8c460e01594e83f21ff5e60cd7a417a1ed618703Mark Andrews# You can obtain a copy of the license at
99bf6a57d9f6b55da6de9c22fb6883a4bf7d569eEvan Hunt# trunk/opends/resource/legal-notices/OpenDS.LICENSE
c548cbbf6b92e4fa5c7c78114c97ef1e50b87379Evan Hunt# See the License for the specific language governing permissions
c548cbbf6b92e4fa5c7c78114c97ef1e50b87379Evan Hunt# and limitations under the License.
e57a83b57659ae1d4f755a7841b519c047ec7f75Evan Hunt# When distributing Covered Code, include this CDDL HEADER in each
e57a83b57659ae1d4f755a7841b519c047ec7f75Evan Hunt# file and include the License file at
e57a83b57659ae1d4f755a7841b519c047ec7f75Evan Hunt# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
e57a83b57659ae1d4f755a7841b519c047ec7f75Evan Hunt# add the following below this CDDL HEADER, with the fields enclosed
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt# by brackets "[]" replaced with your own identifying information:
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt# Portions Copyright [yyyy] [name of copyright owner]
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt# CDDL HEADER END
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt# Copyright 2006-2008 Sun Microsystems, Inc.
bbb3705e4cbdacf7cf6da7e448d79d97fdab2411Mark Andrews# This script may be used to request that the Directory Server shut down.
bbb3705e4cbdacf7cf6da7e448d79d97fdab2411Mark Andrews# It operates in two different ways, depending on how it is invoked. If it
4bf686cf5d6b83981abdf2d8157c829922acc6d4Evan Hunt# is invoked without any arguments and a local PID file is available, then it
4bf686cf5d6b83981abdf2d8157c829922acc6d4Evan Hunt# will stop the server by sending a TERM signal to the process, and this
4bf686cf5d6b83981abdf2d8157c829922acc6d4Evan Hunt# script will wait until the server has stopped before exiting. If any
da4436812c7108dd39e09069d4af770eaa738c7fMark Andrews# arguments were provided or there is no local PID file, then it will attempt
da4436812c7108dd39e09069d4af770eaa738c7fMark Andrews# to stop the server using an LDAP request.
c82da2167dcbd8300f0eaa81fb900c0b17e8f94cMark Andrews# Capture the current working directory so that we can change to it later.
c82da2167dcbd8300f0eaa81fb900c0b17e8f94cMark Andrews# Then capture the location of this script and the Directory Server instance
c82da2167dcbd8300f0eaa81fb900c0b17e8f94cMark Andrews# root so that we can use them to create appropriate paths.
831f59eb43b56642b00f82e07722836d2f9593abEvan Huntcd "${WORKING_DIR}"
831f59eb43b56642b00f82e07722836d2f9593abEvan Hunt# We keep this values to reset the environment before calling start-ds.
a13aa526be16869d1284256fbb2136f4d50ed1d7Evan Hunt# Specify the script name so that we can use the specified java properties.
4eb998928b9aef0ceda42d7529980d658138698aEvan Hunt# Set environment variables
4eb998928b9aef0ceda42d7529980d658138698aEvan Hunt. "${INSTANCE_ROOT}/lib/_script-util.sh"
72c86c105a7cf315036d7131a4ef408bc6227639Evan Hunt"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
72c86c105a7cf315036d7131a4ef408bc6227639Evan Hunt org.opends.server.tools.StopDS --checkStoppability "${@}"
3a0da183bb40bd120698102b20b61ef12665c09bMark Andrews# Already stopped and nothing else to do.
af21fc66447083a01e41e533fe9737ffcf21cc2dMark Andrews # Already stopped and must start locally.
33b8db1bb3f0aa3a39db459e6a32a1082b8dce13Evan Hunt # Stop using system call
9ffd0f0270ef06bd60b1b2754bbeefbe1da33ce7Evan Hunt # Restart using system call
2a184ff86544cc67c36e2ce6bb3ddb5ac44684b8Evan Hunt if test -f "${INSTANCE_ROOT}/logs/server.pid"
2a184ff86544cc67c36e2ce6bb3ddb5ac44684b8Evan Hunt "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
85f89d58a50a86859c04069ea87b2b23b3325d11Evan Hunt echo "ERROR: Unable to find the server.pid file to determine the process"
85f89d58a50a86859c04069ea87b2b23b3325d11Evan Hunt echo " ID of the OpenDS process to terminate."
40a7e85f3ee3bd66a8f87bf8af674e1e48b05396Evan Hunt# Delete the pid file if the server is stopped (this can occur if the process
c548cbbf6b92e4fa5c7c78114c97ef1e50b87379Evan Hunt# has been killed using kill -9).
c548cbbf6b92e4fa5c7c78114c97ef1e50b87379Evan Hunt if test -f "${INSTANCE_ROOT}/logs/server.pid"
bdc7cf66ff626163801cc59b2fd25523da07d238Mark Andrews# Now if the user wants to restart the server, try to restart it if the server
bdc7cf66ff626163801cc59b2fd25523da07d238Mark Andrews# is stopped.
118bdfd8c4b4dbdd47c17afe61e506fefee9c2daMark Andrews# Set the original values that the user had on the environment in order to be
58154043cca0caf03d6fc1a47ed7f24681f24762Evan Hunt# sure that the start-ds script works with the proper arguments (in particular
58154043cca0caf03d6fc1a47ed7f24681f24762Evan Hunt# if the user specified not to overwrite the environment).
55e5c51e661e23e24573db84114a3837817745c9Evan Hunt "${INSTANCE_ROOT}/bin/start-ds"
df925e6c66d45d960fbac0383169763967d2111cEvan Hunt# The user does not want to start the server locally and it is already stopped.
740e7340c55e9f0cf80c6fbbf7e8d3c1bdeaa255Mark Andrews# If we've gotten here, then we should try to stop the server over LDAP.
740e7340c55e9f0cf80c6fbbf7e8d3c1bdeaa255Mark Andrews"${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \