stop-ds revision 4edb61f8b0f8ce9f62d803c706612376498672b4
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#!/bin/sh
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# CDDL HEADER START
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# The contents of this file are subject to the terms of the
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Common Development and Distribution License, Version 1.0 only
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# (the "License"). You may not use this file except in compliance
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# with the License.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# You can obtain a copy of the license at
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# trunk/opends/resource/legal-notices/OpenDS.LICENSE
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# See the License for the specific language governing permissions
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# and limitations under the License.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# When distributing Covered Code, include this CDDL HEADER in each
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# file and include the License file at
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# add the following below this CDDL HEADER, with the fields enclosed
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# by brackets "[]" replaced with your own identifying * information:
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Portions Copyright [yyyy] [name of copyright owner]
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# CDDL HEADER END
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Portions Copyright 2006 Sun Microsystems, Inc.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# This script may be used to request that the Directory Server shut down.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# It operates in two different ways, depending on how it is invoked. If it
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# is invoked without any arguments and a local PID file is available, then it
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# will stop the server by sending a TERM signal to the process, and this
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# script will wait until the server has stopped before exiting. If any
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# arguments were provided or there is no local PID file, then it will attempt
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# to stop the server using an LDAP request.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# See if JAVA_HOME is set. If not, then see if there is a java executable in
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# the path and try to figure it out.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeif test -z "${JAVA_BIN}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipethen
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe if test -z "${JAVA_HOME}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe JAVA_BIN=`which java 2> /dev/null`
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe if test ${?} -eq 0
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe export JAVA_BIN
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe else
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe exit 1
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe else
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe JAVA_BIN=${JAVA_HOME}/bin/java
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe export JAVA_BIN
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipefi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# system environment variables for security and compatibility reasons.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipePATH=/bin:/usr/bin
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_LIBRARY_PATH=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_LIBRARY_PATH_32=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_LIBRARY_PATH_64=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_PRELOAD=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_PRELOAD_32=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeLD_PRELOAD_64=
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Capture the current working directory so that we can change to it later.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Then capture the location of this script and the Directory Server instance
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# root so that we can use them to create appropriate paths.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeWORKING_DIR=`pwd`
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipecd `dirname "${0}"`
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeSCRIPT_DIR=`pwd`
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipecd ..
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeINSTANCE_ROOT=`pwd`
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeexport INSTANCE_ROOT
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipecd "${WORKING_DIR}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Configure the appropriate CLASSPATH.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeCLASSPATH=${INSTANCE_ROOT}/classes
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipefor JAR in ${INSTANCE_ROOT}/lib/*.jar
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipedo
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe CLASSPATH=${CLASSPATH}:${JAR}
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipedone
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeexport CLASSPATH
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# See if any arguments were provided and if a local PID file exists. If there
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# were no arguments and there is a PID file, then try to stop the server with
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# a kill command.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipeif test -z "${1}"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipethen
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe if test -f "${INSTANCE_ROOT}/logs/server.pid"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe kill `cat "${INSTANCE_ROOT}/logs/server.pid"`
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe EXIT_CODE=${?}
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe if test "${EXIT_CODE}" -eq 0
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe "${JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe --logFile "${INSTANCE_ROOT}/logs/errors"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe EXIT_CODE=${?}
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe exit ${EXIT_CODE}
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipefi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# If we've gotten here, then we should try to stop the server over LDAP.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe"${JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.StopDS "${@}"