stop-ds revision 5636
71bd43eebd9d6e42dbcae62b730f5b6508d5acd8Automatic Updater# CDDL HEADER START
59528addd704f8d5757b54e540520f74e588a7c7Automatic Updater# The contents of this file are subject to the terms of the
2bb3422dc683c013db7042f5736240de6b86f182Automatic Updater# Common Development and Distribution License, Version 1.0 only
7b67cfadd077feb0ec3e6c78385ba0d845a9789bMark Andrews# (the "License"). You may not use this file except in compliance
75b70a68aefaa17ac4e768d5ed85d2f50d471490Automatic Updater# with the License.
bb93c8542756719b53096b9939e4041d0966026fAutomatic Updater# You can obtain a copy of the license at
90ff38a0d8deaf5f9c2aa5916d99b2e572d28738Automatic Updater# trunk/opends/resource/legal-notices/OpenDS.LICENSE
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
ac4e70ff8955669341f435bc0a734a17c01af124Mark Andrews# See the License for the specific language governing permissions
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater# and limitations under the License.
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater# When distributing Covered Code, include this CDDL HEADER in each
bc0a53583d92309bebcf93c408e2f3247ebd3d3cAutomatic Updater# file and include the License file at
56874aef380a64a2c183b7c282c3e7a361d67fa1Automatic Updater# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# add the following below this CDDL HEADER, with the fields enclosed
96713299d08c0735c18ebe8772dd2cc1ecd4356aAutomatic Updater# by brackets "[]" replaced with your own identifying information:
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrews# Portions Copyright [yyyy] [name of copyright owner]
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# CDDL HEADER END
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# Copyright 2006-2009 Sun Microsystems, Inc.
efb0e886f18894a1d2489f1ad74ad14b579e11c7Mark Andrews# Portions Copyright 2011 ForgeRock AS
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson# This script may be used to request that the Directory Server shut down.
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# It operates in two different ways, depending on how it is invoked. If it
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# is invoked without any arguments and a local PID file is available, then it
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson# will stop the server by sending a TERM signal to the process, and this
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# script will wait until the server has stopped before exiting. If any
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# arguments were provided or there is no local PID file, then it will attempt
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater# to stop the server using an LDAP request.
80faf1588895fd26490f82f95a7a1b771df1c324Automatic Updater# Capture the current working directory so that we can change to it later.
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# Then capture the location of this script and the Directory Server instance
59528addd704f8d5757b54e540520f74e588a7c7Automatic Updater# root so that we can use them to create appropriate paths.
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrewscd "${WORKING_DIR}"
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# We keep this values to reset the environment before calling start-ds.
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# Specify the script name so that we can use the specified java properties.
bb93c8542756719b53096b9939e4041d0966026fAutomatic Updater# check for presence of lib/_svc-opendj.sh file
723bfc0fc28c486c805de016c4475a35328eb8abAutomatic Updater# If present, we should be on Solaris/OpenSolaris and use SMF to start
723bfc0fc28c486c805de016c4475a35328eb8abAutomatic Updater# Check --exec. If not present, start OpenDJ from SMF
723bfc0fc28c486c805de016c4475a35328eb8abAutomatic Updaterif test -f "${INSTALL_ROOT}/lib/_svc-opendj.sh"
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews elif [ "$1" != "-V" -a "$1" != "--version" -a "$1" != "-?" -a \
7af91d15b2ce1ce32f7320f6d5cc3b83621c241aAutomatic Updater#These options are not stopping the server, but checking version and help
7af91d15b2ce1ce32f7320f6d5cc3b83621c241aAutomatic Updater /usr/sbin/svcadm disable -t svc:/network/ldap/server:opendj
fe80a4909bf62b602feaf246866e9d29f7654194Automatic Updater exec /usr/sbin/svcadm enable -t svc:/network/ldap/server:opendj
fe80a4909bf62b602feaf246866e9d29f7654194Automatic Updater exec /usr/sbin/svcadm disable -t svc:/network/ldap/server:opendj
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson# Set environment variables
aa1d397c4736cd86540555193d71e55fa3b37b2aMark AndrewsSCRIPT_UTIL_CMD=set-full-environment-and-test-java
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson. "${INSTALL_ROOT}/lib/_script-util.sh"
2bb3422dc683c013db7042f5736240de6b86f182Automatic Updater"${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
59528addd704f8d5757b54e540520f74e588a7c7Automatic Updater org.opends.server.tools.StopDS --checkStoppability "${@}"
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater# Already stopped and nothing else to do.
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater # Already stopped and must start locally.
59528addd704f8d5757b54e540520f74e588a7c7Automatic Updater # Stop using system call
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater # Restart using system call
7f94d9a8162c9a96b56e66176702b66e79d8e1a2Automatic Updaterif test ${MUST_STOP_USING_SYSTEM_CALL} -eq 0
7f94d9a8162c9a96b56e66176702b66e79d8e1a2Automatic Updater if test -f "${INSTANCE_ROOT}/logs/server.pid"
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater read PID < "${INSTANCE_ROOT}/logs/server.pid"
59528addd704f8d5757b54e540520f74e588a7c7Automatic Updater "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington echo "ERROR: Unable to find the server.pid file to determine the process"
f0ecd0e64ffa2a8afef95d81275d46a845f15402Automatic Updater echo " ID of the OpenDJ process to terminate."
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# Delete the pid file if the server is stopped (this can occur if the process
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson# has been killed using kill -9).
8ae412a86ed138263796195eed82a4716e7effcbMark Andrews if test -f "${INSTANCE_ROOT}/logs/server.pid"
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# Now if the user wants to restart the server, try to restart it if the server
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updaterif test ${MUST_START_USING_SYSTEM_CALL} -eq 0
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrews# Set the original values that the user had on the environment in order to be
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# sure that the start-ds script works with the proper arguments (in particular
e076d0c88be69de7c190ab924d095e69d2e11f7aAndreas Gustafsson# if the user specified not to overwrite the environment).
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson "${INSTALL_ROOT}/bin/start-ds"
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# The user does not want to start the server locally and it is already stopped.
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater# If we've gotten here, then we should try to stop the server over LDAP.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington"${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \