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