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