stop-ds revision 832
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#!/bin/sh
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# CDDL HEADER START
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# The contents of this file are subject to the terms of the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Common Development and Distribution License, Version 1.0 only
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# (the "License"). You may not use this file except in compliance
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# with the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# You can obtain a copy of the license at
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# trunk/opends/resource/legal-notices/OpenDS.LICENSE
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# See the License for the specific language governing permissions
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# and limitations under the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# When distributing Covered Code, include this CDDL HEADER in each
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# file and include the License file at
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# add the following below this CDDL HEADER, with the fields enclosed
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# by brackets "[]" replaced with your own identifying * information:
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Portions Copyright [yyyy] [name of copyright owner]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# CDDL HEADER END
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Portions Copyright 2006 Sun Microsystems, Inc.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# This script may be used to request that the Directory Server shut down.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# It operates in two different ways, depending on how it is invoked. If it
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# is invoked without any arguments and a local PID file is available, then it
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# will stop the server by sending a TERM signal to the process, and this
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# script will wait until the server has stopped before exiting. If any
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# arguments were provided or there is no local PID file, then it will attempt
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# to stop the server using an LDAP request.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Capture the current working directory so that we can change to it later.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Then capture the location of this script and the Directory Server instance
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# root so that we can use them to create appropriate paths.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinWORKING_DIR=`pwd`
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chincd `dirname "${0}"`
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinSCRIPT_DIR=`pwd`
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chincd ..
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinINSTANCE_ROOT=`pwd`
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinexport INSTANCE_ROOT
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chincd "${WORKING_DIR}"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# See if JAVA_HOME is set. If not, then see if there is a java executable in
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# the path and try to figure it out.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif test -z "${JAVA_BIN}"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if test -z "${JAVA_HOME}"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if test -f "${INSTANCE_ROOT}/bin/set-java-home"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin . "${INSTANCE_ROOT}/bin/set-java-home"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin JAVA_BIN="${JAVA_HOME}/bin/java"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin export JAVA_BIN
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin JAVA_BIN=`which java 2> /dev/null`
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if test ${?} -eq 0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin export JAVA_BIN
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin exit 1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fi
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fi
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin JAVA_BIN="${JAVA_HOME}/bin/java"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin export JAVA_BIN
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fi
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfi
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# system environment variables for security and compatibility reasons.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinPATH=/bin:/usr/bin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinLD_LIBRARY_PATH=
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland MainzLD_LIBRARY_PATH_32=
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinLD_LIBRARY_PATH_64=
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinLD_PRELOAD=
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinLD_PRELOAD_32=
7c2fbfb345896881c631598ee3852ce9ce33fb07April ChinLD_PRELOAD_64=
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Configure the appropriate CLASSPATH.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinCLASSPATH=${INSTANCE_ROOT}/classes
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfor JAR in ${INSTANCE_ROOT}/lib/*.jar
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chindo
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin CLASSPATH=${CLASSPATH}:${JAR}
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzdone
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzexport CLASSPATH
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Specify the script name so that it may be provided in command-line usage.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinSCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=stop-ds"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinexport SCRIPT_NAME_ARG
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# See if any arguments were provided and if a local PID file exists. If there
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# were no arguments (or only the -R argument was passed) and there is a PID
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# file, then try to stop the server with a kill command.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinNO_ARG_OR_ONLY_RESTART=1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinRESTART=0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfor ARG in "${@}"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chindo
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if test "${ARG}" != "-R"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if test "${ARG}" != "--restart"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin NO_ARG_OR_ONLY_RESTART=0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin RESTART=1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fi
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin RESTART=1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fi
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chindone
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif test ${NO_ARG_OR_ONLY_RESTART} -eq 1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if test -f "${INSTANCE_ROOT}/logs/server.pid"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin kill `cat "${INSTANCE_ROOT}/logs/server.pid"`
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin EXIT_CODE=${?}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if test "${EXIT_CODE}" -eq 0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "${JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin --logFile "${INSTANCE_ROOT}/logs/errors"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin EXIT_CODE=${?}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if test "${RESTART}" -eq 1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if test "${EXIT_CODE}" -eq 0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "${INSTANCE_ROOT}/bin/start-ds"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin EXIT_CODE=${?}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fi
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fi
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fi
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin exit ${EXIT_CODE}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fi
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfi
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# If we've gotten here, then we should try to stop the server over LDAP.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin org.opends.server.tools.StopDS "${@}"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin