stop-ds revision 014019918f7e3844f558f6159b8d41517254edc2
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#!/bin/sh
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# CDDL HEADER START
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# The contents of this file are subject to the terms of the
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# Common Development and Distribution License, Version 1.0 only
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# (the "License"). You may not use this file except in compliance
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# with the License.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# You can obtain a copy of the license at
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# trunk/opends/resource/legal-notices/OpenDS.LICENSE
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# See the License for the specific language governing permissions
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# and limitations under the License.
923784d59ac065eee98b208dfacda6fbc24c71d6Jake Feasel#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# When distributing Covered Code, include this CDDL HEADER in each
4eb529f0471672590d77cf89ef23987ba2c95ff4Laszlo Hordos# file and include the License file at
4eb529f0471672590d77cf89ef23987ba2c95ff4Laszlo Hordos# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# add the following below this CDDL HEADER, with the fields enclosed
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# by brackets "[]" replaced with your own identifying information:
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# Portions Copyright [yyyy] [name of copyright owner]
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# CDDL HEADER END
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan#
7c64421614d420f1951773af3ce6a6111cef84b2Jake Feasel#
7c64421614d420f1951773af3ce6a6111cef84b2Jake Feasel# Copyright 2006-2008 Sun Microsystems, Inc.
7c64421614d420f1951773af3ce6a6111cef84b2Jake Feasel
7c64421614d420f1951773af3ce6a6111cef84b2Jake Feasel
b564baaca75789be41eba24bb96e31f3ce5b10eeJake Feasel# This script may be used to request that the Directory Server shut down.
7c64421614d420f1951773af3ce6a6111cef84b2Jake Feasel# It operates in two different ways, depending on how it is invoked. If it
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# is invoked without any arguments and a local PID file is available, then it
54f30b716553d88ea9ebb010037f4c74eb1d69acPaul Bryan# will stop the server by sending a TERM signal to the process, and this
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan# script will wait until the server has stopped before exiting. If any
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos# arguments were provided or there is no local PID file, then it will attempt
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos# to stop the server using an LDAP request.
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos# Capture the current working directory so that we can change to it later.
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos# Then capture the location of this script and the Directory Server instance
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos# root so that we can use them to create appropriate paths.
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo HordosWORKING_DIR=`pwd`
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordoscd "`dirname "${0}"`"
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo HordosSCRIPT_DIR=`pwd`
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordos
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordoscd ..
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo HordosINSTALL_ROOT=`pwd`
e5c203467ee4398ae81a6adb63da7477451b2e77Laszlo Hordosexport INSTALL_ROOT
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordosif cat ${INSTALL_ROOT}/instance.loc | grep '^/' > /dev/null
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordosthen
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos INSTANCE_ROOT=`cat ${INSTALL_ROOT}/instance.loc`
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos export INSTANCE_ROOT
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordoselse
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos INSTANCE_ROOT=${INSTALL_ROOT}/`cat ${INSTALL_ROOT}/instance.loc`
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos export INSTANCE_ROOT
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordosfi
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordos
8166b048bd3e2106dbdeaa1a2b8a728952d788f4Laszlo Hordoscd "${WORKING_DIR}"
1965c5d21403c3d66eb1efa29c670378311b1077Paul Bryan
a14db14686bf9f6817c47e5c14e887d74dd615f0Laszlo Hordos# We keep this values to reset the environment before calling start-ds.
13ec3d949d0a30c6d8fa0b899f583d64164f37f3Chris DrakeORIGINAL_JAVA_ARGS=${OPENDS_JAVA_ARGS}
f85a185a657def022f6d8896cc755403f7d40694Andi EgloffORIGINAL_JAVA_HOME=${OPENDS_JAVA_HOME}
a14db14686bf9f6817c47e5c14e887d74dd615f0Laszlo HordosORIGINAL_JAVA_BIN=${OPENDS_JAVA_BIN}
2d7019e19039fd083850f76e54b6b26a7b06a8f2yaromin
2d7019e19039fd083850f76e54b6b26a7b06a8f2yaromin
099518f7f744f2eaa4e23d3e0a92110f2e5e2811omebold# Specify the script name so that we can use the specified java properties.
2d7019e19039fd083850f76e54b6b26a7b06a8f2yarominSCRIPT_NAME="stop-ds"
00689490237ac7e37aa116d443e4e5882c5552dcMatthias Tristlexport SCRIPT_NAME
00689490237ac7e37aa116d443e4e5882c5552dcMatthias Tristl
2d7019e19039fd083850f76e54b6b26a7b06a8f2yaromin# Set environment variables
2d7019e19039fd083850f76e54b6b26a7b06a8f2yarominSCRIPT_UTIL_CMD=set-full-environment-and-test-java
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordosexport SCRIPT_UTIL_CMD
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel. "${INSTALL_ROOT}/lib/_script-util.sh"
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo HordosRETURN_CODE=$?
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordosif test ${RETURN_CODE} -ne 0
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordosthen
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos exit ${RETURN_CODE}
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordosfi
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos org.opends.server.tools.StopDS --checkStoppability "${@}"
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake FeaselEC=${?}
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake FeaselSTOPPED=1
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake FeaselEXIT_CODE=1
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake FeaselMUST_START_USING_SYSTEM_CALL=1
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake FeaselMUST_STOP_USING_SYSTEM_CALL=1
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake FeaselQUIET_MODE=1
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordosif test ${EC} -eq 98
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos#
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos# Already stopped and nothing else to do.
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos#
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordosthen
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos STOPPED=0
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordoselse
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos if test ${EC} -eq 99 -o ${EC} -eq 105
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos #
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos # Already stopped and must start locally.
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos #
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos then
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos STOPPED=0
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos MUST_START_USING_SYSTEM_CALL=0
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel if test ${EC} -eq 105
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel then
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel QUIET_MODE=0
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel fi
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos else
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos if test ${EC} -eq 100
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel then
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel #
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel # Stop using system call
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel #
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel MUST_STOP_USING_SYSTEM_CALL=0
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel else
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel if test ${EC} -eq 101 -o ${EC} -eq 106
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos then
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos #
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos # Restart using system call
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos #
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos MUST_STOP_USING_SYSTEM_CALL=0
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos MUST_START_USING_SYSTEM_CALL=0
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos if test ${EC} -eq 106
660a40ad15749d74efa0dd4ef12cb8781c570e22Laszlo Hordos then
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl QUIET_MODE=0
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl fi
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl else
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl if test ${EC} -ne 102
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl then
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl exit ${EC}
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel fi
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel fi
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel fi
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel fi
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlfi
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feaselif test ${MUST_STOP_USING_SYSTEM_CALL} -eq 0
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feaselthen
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel if test -f "${INSTANCE_ROOT}/logs/server.pid"
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel then
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel kill `cat "${INSTANCE_ROOT}/logs/server.pid"`
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel EXIT_CODE=${?}
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel if test ${EXIT_CODE} -eq 0
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl then
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl --logFile "${INSTANCE_ROOT}/logs/errors"
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl EXIT_CODE=${?}
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl if test ${EXIT_CODE} -eq 0
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl then
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl STOPPED=0
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl fi
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl fi
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl else
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl echo "ERROR: Unable to find the server.pid file to determine the process"
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl echo " ID of the OpenDS process to terminate."
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl exit 1
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel fi
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feaselfi
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel# Delete the pid file if the server is stopped (this can occur if the process
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl# has been killed using kill -9).
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlif test ${STOPPED} -eq 0
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feaselthen
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel if test -f "${INSTANCE_ROOT}/logs/server.pid"
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel then
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel rm "${INSTANCE_ROOT}/logs/server.pid"
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel fi
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feaselfi
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl# Now if the user wants to restart the server, try to restart it if the server
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl# is stopped.
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlif test ${MUST_START_USING_SYSTEM_CALL} -eq 0
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlthen
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl if test ${STOPPED} -eq 0
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl then
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl# Set the original values that the user had on the environment in order to be
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl# sure that the start-ds script works with the proper arguments (in particular
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl# if the user specified not to overwrite the environment).
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl OPENDS_JAVA_ARGS=${ORIGINAL_JAVA_ARGS}
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl OPENDS_JAVA_HOME=${ORIGINAL_JAVA_HOME}
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl OPENDS_JAVA_BIN=${ORIGINAL_JAVA_BIN}
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl if test ${QUIET_MODE} -eq 0
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl then
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel "${INSTALL_ROOT}/bin/start-ds" --quiet
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel EXIT_CODE=${?}
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel exit ${EXIT_CODE}
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel else
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl "${INSTALL_ROOT}/bin/start-ds"
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl EXIT_CODE=${?}
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel exit ${EXIT_CODE}
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel fi
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel fi
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel#
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel# The user does not want to start the server locally and it is already stopped.
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel# Just exit.
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel#
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlelse
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl if test ${STOPPED} -eq 0
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl then
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl exit 0
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl fi
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristlfi
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl# If we've gotten here, then we should try to stop the server over LDAP.
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl"${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
8698e80519313c98c8d5c6de06ae04cdfc816cafMatthias Tristl org.opends.server.tools.StopDS "${@}"
7d83b6a03bd7b63f2eb6404d6cc1e4c074391ea7Jake Feasel