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