stop-ds revision 3488
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#
3233N/A# Copyright 2006-2008 Sun Microsystems, Inc.
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
486N/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
3488N/Acd "`dirname "${0}"`"
619N/ASCRIPT_DIR=`pwd`
619N/A
619N/Acd ..
619N/AINSTANCE_ROOT=`pwd`
619N/Aexport INSTANCE_ROOT
619N/A
619N/Acd "${WORKING_DIR}"
619N/A
3196N/A# We keep this values to reset the environment before calling start-ds.
3196N/AORIGINAL_JAVA_ARGS=${OPENDS_JAVA_ARGS}
3196N/AORIGINAL_JAVA_HOME=${OPENDS_JAVA_HOME}
3196N/AORIGINAL_JAVA_BIN=${OPENDS_JAVA_BIN}
486N/A
486N/A
2976N/A# Specify the script name so that we can use the specified java properties.
2976N/ASCRIPT_NAME="stop-ds"
2976N/Aexport SCRIPT_NAME
486N/A
2976N/A# Set environment variables
2976N/ASCRIPT_UTIL_CMD=set-full-environment-and-test-java
2976N/Aexport SCRIPT_UTIL_CMD
2976N/A. "${INSTANCE_ROOT}/lib/_script-util.sh"
2976N/ARETURN_CODE=$?
2976N/Aif test ${RETURN_CODE} -ne 0
1181N/Athen
2976N/A exit ${RETURN_CODE}
1181N/Afi
536N/A
2976N/A
3196N/A"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
961N/A org.opends.server.tools.StopDS --checkStoppability "${@}"
961N/AEC=${?}
832N/A
961N/ASTOPPED=1
961N/AEXIT_CODE=1
961N/AMUST_START_USING_SYSTEM_CALL=1
961N/AMUST_STOP_USING_SYSTEM_CALL=1
2296N/AQUIET_MODE=1
961N/A
961N/Aif test ${EC} -eq 98
961N/A#
961N/A# Already stopped and nothing else to do.
961N/A#
486N/Athen
857N/A STOPPED=0
961N/Aelse
2296N/A if test ${EC} -eq 99 -o ${EC} -eq 105
961N/A #
961N/A # Already stopped and must start locally.
961N/A #
486N/A then
961N/A STOPPED=0
961N/A MUST_START_USING_SYSTEM_CALL=0
2296N/A if test ${EC} -eq 105
2296N/A then
2296N/A QUIET_MODE=0
2296N/A fi
961N/A else
961N/A if test ${EC} -eq 100
486N/A then
961N/A #
961N/A # Stop using system call
961N/A #
961N/A MUST_STOP_USING_SYSTEM_CALL=0
961N/A else
2296N/A if test ${EC} -eq 101 -o ${EC} -eq 106
961N/A then
961N/A #
961N/A # Restart using system call
961N/A #
961N/A MUST_STOP_USING_SYSTEM_CALL=0
961N/A MUST_START_USING_SYSTEM_CALL=0
2296N/A if test ${EC} -eq 106
2296N/A then
2296N/A QUIET_MODE=0
2296N/A fi
961N/A else
961N/A if test ${EC} -ne 102
832N/A then
961N/A exit ${EC}
832N/A fi
961N/A fi
857N/A fi
857N/A fi
961N/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"
857N/A then
961N/A kill `cat "${INSTANCE_ROOT}/logs/server.pid"`
961N/A EXIT_CODE=${?}
961N/A if test ${EXIT_CODE} -eq 0
961N/A then
2650N/A "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
961N/A --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
961N/A --logFile "${INSTANCE_ROOT}/logs/errors"
961N/A EXIT_CODE=${?}
961N/A if test ${EXIT_CODE} -eq 0
961N/A then
961N/A STOPPED=0
961N/A fi
486N/A fi
2230N/A else
2230N/A echo "ERROR: Unable to find the server.pid file to determine the process"
2230N/A echo " ID of the OpenDS process to terminate."
2230N/A exit 1
486N/A fi
486N/Afi
486N/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
961N/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
3196N/A# Set the original values that the user had on the environment in order to be
3196N/A# sure that the start-ds script works with the proper arguments (in particular
3196N/A# if the user specified not to overwrite the environment).
3196N/A OPENDS_JAVA_ARGS=${ORIGINAL_JAVA_ARGS}
3196N/A OPENDS_JAVA_HOME=${ORIGINAL_JAVA_HOME}
3196N/A OPENDS_JAVA_BIN=${ORIGINAL_JAVA_BIN}
2296N/A if test ${QUIET_MODE} -eq 0
2296N/A then
2296N/A "${INSTANCE_ROOT}/bin/start-ds" --quiet
2296N/A EXIT_CODE=${?}
2296N/A exit ${EXIT_CODE}
2296N/A else
2296N/A "${INSTANCE_ROOT}/bin/start-ds"
2296N/A EXIT_CODE=${?}
2296N/A exit ${EXIT_CODE}
2296N/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
961N/A exit 0
961N/A fi
961N/Afi
486N/A
486N/A# If we've gotten here, then we should try to stop the server over LDAP.
2650N/A"${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
961N/A org.opends.server.tools.StopDS "${@}"