stop-ds revision 814920a099ee946453263e682c7bb2cda00b7983
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce#!/bin/sh
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce#
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# CDDL HEADER START
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce#
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# The contents of this file are subject to the terms of the
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce# Common Development and Distribution License, Version 1.0 only
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce# (the "License"). You may not use this file except in compliance
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce# with the License.
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce#
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# You can obtain a copy of the license at
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# trunk/opends/resource/legal-notices/OpenDS.LICENSE
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# See the License for the specific language governing permissions
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# and limitations under the License.
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce#
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# When distributing Covered Code, include this CDDL HEADER in each
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# file and include the License file at
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# add the following below this CDDL HEADER, with the fields enclosed
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# by brackets "[]" replaced with your own identifying information:
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# Portions Copyright [yyyy] [name of copyright owner]
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce#
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# CDDL HEADER END
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce#
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce#
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# Copyright 2006-2009 Sun Microsystems, Inc.
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# Portions Copyright 2011 ForgeRock AS
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# This script may be used to request that the Directory Server shut down.
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# It operates in two different ways, depending on how it is invoked. If it
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# is invoked without any arguments and a local PID file is available, then it
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# will stop the server by sending a TERM signal to the process, and this
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# script will wait until the server has stopped before exiting. If any
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# arguments were provided or there is no local PID file, then it will attempt
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# to stop the server using an LDAP request.
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# Capture the current working directory so that we can change to it later.
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# Then capture the location of this script and the Directory Server instance
cac133768c18c89d4fccd4fc65d1a95232b51406bryce# root so that we can use them to create appropriate paths.
cac133768c18c89d4fccd4fc65d1a95232b51406bryceWORKING_DIR=`pwd`
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce
7923e87a291880ac8293fb5d1a1e1b759b23a091brycecd "`dirname "${0}"`"
7923e87a291880ac8293fb5d1a1e1b759b23a091bryceSCRIPT_DIR=`pwd`
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce
7923e87a291880ac8293fb5d1a1e1b759b23a091brycecd ..
7923e87a291880ac8293fb5d1a1e1b759b23a091bryceINSTALL_ROOT=`pwd`
7923e87a291880ac8293fb5d1a1e1b759b23a091bryceexport INSTALL_ROOT
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce
7923e87a291880ac8293fb5d1a1e1b759b23a091brycecd "${WORKING_DIR}"
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce# We keep this values to reset the environment before calling start-ds.
7923e87a291880ac8293fb5d1a1e1b759b23a091bryceORIGINAL_JAVA_ARGS=${OPENDS_JAVA_ARGS}
7923e87a291880ac8293fb5d1a1e1b759b23a091bryceORIGINAL_JAVA_HOME=${OPENDS_JAVA_HOME}
7923e87a291880ac8293fb5d1a1e1b759b23a091bryceORIGINAL_JAVA_BIN=${OPENDS_JAVA_BIN}
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce# Specify the script name so that we can use the specified java properties.
7923e87a291880ac8293fb5d1a1e1b759b23a091bryceSCRIPT_NAME="stop-ds"
7923e87a291880ac8293fb5d1a1e1b759b23a091bryceexport SCRIPT_NAME
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce
cac133768c18c89d4fccd4fc65d1a95232b51406bryce# check for presence of lib/_svc-opendj.sh file
cac133768c18c89d4fccd4fc65d1a95232b51406bryce# If present, we should be on Solaris/OpenSolaris and use SMF to start
cac133768c18c89d4fccd4fc65d1a95232b51406bryce# OpenDJ.
cac133768c18c89d4fccd4fc65d1a95232b51406bryce# Check --exec. If not present, start OpenDJ from SMF
cac133768c18c89d4fccd4fc65d1a95232b51406bryceif test -f "${INSTALL_ROOT}/lib/_svc-opendj.sh"
cac133768c18c89d4fccd4fc65d1a95232b51406brycethen
cac133768c18c89d4fccd4fc65d1a95232b51406bryce if [ "$1" = "--exec" ]
cac133768c18c89d4fccd4fc65d1a95232b51406bryce then
cac133768c18c89d4fccd4fc65d1a95232b51406bryce shift
cac133768c18c89d4fccd4fc65d1a95232b51406bryce elif [ "$1" != "-V" -a "$1" != "--version" -a "$1" != "-?" -a \
cac133768c18c89d4fccd4fc65d1a95232b51406bryce "$1" != "-H" -a "$1" != "--help" ]
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce#These options are not stopping the server, but checking version and help
cac133768c18c89d4fccd4fc65d1a95232b51406bryce then
cac133768c18c89d4fccd4fc65d1a95232b51406bryce if [ "$1" = "-R" -o "$1" = "--restart" ]
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce then
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce /usr/sbin/svcadm disable -t svc:/network/ldap/server:opendj
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce RETURN_CODE=$?
cac133768c18c89d4fccd4fc65d1a95232b51406bryce if test ${RETURN_CODE} -ne 0
cac133768c18c89d4fccd4fc65d1a95232b51406bryce then
cac133768c18c89d4fccd4fc65d1a95232b51406bryce exit ${RETURN_CODE}
cac133768c18c89d4fccd4fc65d1a95232b51406bryce fi
cac133768c18c89d4fccd4fc65d1a95232b51406bryce exec /usr/sbin/svcadm enable -t svc:/network/ldap/server:opendj
cac133768c18c89d4fccd4fc65d1a95232b51406bryce else
cac133768c18c89d4fccd4fc65d1a95232b51406bryce exec /usr/sbin/svcadm disable -t svc:/network/ldap/server:opendj
cac133768c18c89d4fccd4fc65d1a95232b51406bryce fi
cac133768c18c89d4fccd4fc65d1a95232b51406bryce fi
cac133768c18c89d4fccd4fc65d1a95232b51406brycefi
cac133768c18c89d4fccd4fc65d1a95232b51406bryce
cac133768c18c89d4fccd4fc65d1a95232b51406bryce# Set environment variables
cac133768c18c89d4fccd4fc65d1a95232b51406bryceSCRIPT_UTIL_CMD=set-full-environment-and-test-java
cac133768c18c89d4fccd4fc65d1a95232b51406bryceexport SCRIPT_UTIL_CMD
cac133768c18c89d4fccd4fc65d1a95232b51406bryce. "${INSTALL_ROOT}/lib/_script-util.sh"
cac133768c18c89d4fccd4fc65d1a95232b51406bryceRETURN_CODE=$?
cac133768c18c89d4fccd4fc65d1a95232b51406bryceif test ${RETURN_CODE} -ne 0
cac133768c18c89d4fccd4fc65d1a95232b51406brycethen
cac133768c18c89d4fccd4fc65d1a95232b51406bryce exit ${RETURN_CODE}
cac133768c18c89d4fccd4fc65d1a95232b51406brycefi
cac133768c18c89d4fccd4fc65d1a95232b51406bryce
cac133768c18c89d4fccd4fc65d1a95232b51406bryce
cac133768c18c89d4fccd4fc65d1a95232b51406bryce"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
cac133768c18c89d4fccd4fc65d1a95232b51406bryce org.opends.server.tools.StopDS --checkStoppability "${@}"
cac133768c18c89d4fccd4fc65d1a95232b51406bryceEC=${?}
cac133768c18c89d4fccd4fc65d1a95232b51406bryce
cac133768c18c89d4fccd4fc65d1a95232b51406bryceSTOPPED=1
cac133768c18c89d4fccd4fc65d1a95232b51406bryceEXIT_CODE=1
cac133768c18c89d4fccd4fc65d1a95232b51406bryceMUST_START_USING_SYSTEM_CALL=1
cac133768c18c89d4fccd4fc65d1a95232b51406bryceMUST_STOP_USING_SYSTEM_CALL=1
cac133768c18c89d4fccd4fc65d1a95232b51406bryceQUIET_MODE=1
cac133768c18c89d4fccd4fc65d1a95232b51406bryce
cac133768c18c89d4fccd4fc65d1a95232b51406bryceif test ${EC} -eq 98
7923e87a291880ac8293fb5d1a1e1b759b23a091bryce#
cac133768c18c89d4fccd4fc65d1a95232b51406bryce# Already stopped and nothing else to do.
cac133768c18c89d4fccd4fc65d1a95232b51406bryce#
cac133768c18c89d4fccd4fc65d1a95232b51406brycethen
cac133768c18c89d4fccd4fc65d1a95232b51406bryce STOPPED=0
cac133768c18c89d4fccd4fc65d1a95232b51406bryceelse
cac133768c18c89d4fccd4fc65d1a95232b51406bryce if test ${EC} -eq 99 -o ${EC} -eq 105
cac133768c18c89d4fccd4fc65d1a95232b51406bryce #
cac133768c18c89d4fccd4fc65d1a95232b51406bryce # Already stopped and must start locally.
cac133768c18c89d4fccd4fc65d1a95232b51406bryce #
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce then
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce STOPPED=0
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce MUST_START_USING_SYSTEM_CALL=0
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce if test ${EC} -eq 105
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce then
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce QUIET_MODE=0
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce fi
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce else
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce if test ${EC} -eq 100
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce then
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce #
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce # Stop using system call
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce #
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce MUST_STOP_USING_SYSTEM_CALL=0
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce else
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce if test ${EC} -eq 101 -o ${EC} -eq 106
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce then
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce #
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce # Restart using system call
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce #
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce MUST_STOP_USING_SYSTEM_CALL=0
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce MUST_START_USING_SYSTEM_CALL=0
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce if test ${EC} -eq 106
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce then
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce QUIET_MODE=0
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce fi
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce else
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce if test ${EC} -ne 102
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce then
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce exit ${EC}
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce fi
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce fi
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce fi
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce fi
72ba327677b00dc4013e4ca19dd5ac4b87da63cebrycefi
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryceif test ${MUST_STOP_USING_SYSTEM_CALL} -eq 0
72ba327677b00dc4013e4ca19dd5ac4b87da63cebrycethen
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce if test -f "${INSTANCE_ROOT}/logs/server.pid"
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce then
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce read PID < "${INSTANCE_ROOT}/logs/server.pid"
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce kill ${PID}
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce EXIT_CODE=${?}
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce if test ${EXIT_CODE} -eq 0
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce then
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce "${OPENDS_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce --logFile "${INSTANCE_ROOT}/logs/errors"
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce EXIT_CODE=${?}
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce if test ${EXIT_CODE} -eq 0
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce then
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce STOPPED=0
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce fi
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce fi
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce else
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce echo "ERROR: Unable to find the server.pid file to determine the process"
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce echo " ID of the OpenDJ process to terminate."
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce exit 1
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce fi
3114ead9a60b65191e92dea6c76c038c03a8f1dcbrycefi
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# Delete the pid file if the server is stopped (this can occur if the process
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# has been killed using kill -9).
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryceif test ${STOPPED} -eq 0
72ba327677b00dc4013e4ca19dd5ac4b87da63cebrycethen
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce if test -f "${INSTANCE_ROOT}/logs/server.pid"
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce then
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce rm "${INSTANCE_ROOT}/logs/server.pid"
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce fi
72ba327677b00dc4013e4ca19dd5ac4b87da63cebrycefi
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce# Now if the user wants to restart the server, try to restart it if the server
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce# is stopped.
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryceif test ${MUST_START_USING_SYSTEM_CALL} -eq 0
72ba327677b00dc4013e4ca19dd5ac4b87da63cebrycethen
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce if test ${STOPPED} -eq 0
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce then
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce# Set the original values that the user had on the environment in order to be
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce# sure that the start-ds script works with the proper arguments (in particular
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce# if the user specified not to overwrite the environment).
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce OPENDS_JAVA_ARGS=${ORIGINAL_JAVA_ARGS}
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce OPENDS_JAVA_HOME=${ORIGINAL_JAVA_HOME}
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce OPENDS_JAVA_BIN=${ORIGINAL_JAVA_BIN}
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce if test ${QUIET_MODE} -eq 0
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce then
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce "${INSTALL_ROOT}/bin/start-ds" --quiet
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce EXIT_CODE=${?}
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce exit ${EXIT_CODE}
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce else
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce "${INSTALL_ROOT}/bin/start-ds"
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce EXIT_CODE=${?}
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce exit ${EXIT_CODE}
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce fi
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce fi
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce#
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce# The user does not want to start the server locally and it is already stopped.
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce# Just exit.
72ba327677b00dc4013e4ca19dd5ac4b87da63cebryce#
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryceelse
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce if test ${STOPPED} -eq 0
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce then
cac133768c18c89d4fccd4fc65d1a95232b51406bryce exit 0
cac133768c18c89d4fccd4fc65d1a95232b51406bryce fi
cac133768c18c89d4fccd4fc65d1a95232b51406brycefi
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce# If we've gotten here, then we should try to stop the server over LDAP.
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce org.opends.server.tools.StopDS "${@}"
3114ead9a60b65191e92dea6c76c038c03a8f1dcbryce