stop-ds revision 4edb61f8b0f8ce9f62d803c706612376498672b4
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#!/bin/sh
bec154197d3d640b0d5b416cd5218ea58dca5d3aTinderbox User#
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# CDDL HEADER START
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#
4a14ce5ba00ab7bc55c99ffdcf59c7a4ab902721Automatic Updater# The contents of this file are subject to the terms of the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# Common Development and Distribution License, Version 1.0 only
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# (the "License"). You may not use this file except in compliance
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# with the License.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# You can obtain a copy of the license at
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# trunk/opends/resource/legal-notices/OpenDS.LICENSE
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# See the License for the specific language governing permissions
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# and limitations under the License.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# When distributing Covered Code, include this CDDL HEADER in each
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox User# file and include the License file at
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# add the following below this CDDL HEADER, with the fields enclosed
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# by brackets "[]" replaced with your own identifying * information:
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# Portions Copyright [yyyy] [name of copyright owner]
e21a2904f02a03fa06b6db04d348f65fe9c67b2bMark Andrews#
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# CDDL HEADER END
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater#
c3dc968140ab7f04795acc7835e4e89ccb0c0a27Tinderbox User# Portions Copyright 2006 Sun Microsystems, Inc.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# This script may be used to request that the Directory Server shut down.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# It operates in two different ways, depending on how it is invoked. If it
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# is invoked without any arguments and a local PID file is available, then it
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# will stop the server by sending a TERM signal to the process, and this
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# script will wait until the server has stopped before exiting. If any
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater# arguments were provided or there is no local PID file, then it will attempt
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# to stop the server using an LDAP request.
c3dc968140ab7f04795acc7835e4e89ccb0c0a27Tinderbox User
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# See if JAVA_HOME is set. If not, then see if there is a java executable in
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# the path and try to figure it out.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsif test -z "${JAVA_BIN}"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsthen
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if test -z "${JAVA_HOME}"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews then
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews JAVA_BIN=`which java 2> /dev/null`
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews if test ${?} -eq 0
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews then
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews export JAVA_BIN
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews else
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
97e74139b19368e385a3564746d42db70879195eAutomatic Updater exit 1
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews fi
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews else
c986916269e0d9ca0a31efb62ff5ac06938815dbTinderbox User JAVA_BIN=${JAVA_HOME}/bin/java
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews export JAVA_BIN
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews fi
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsfi
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# system environment variables for security and compatibility reasons.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark AndrewsPATH=/bin:/usr/bin
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark AndrewsLD_LIBRARY_PATH=
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark AndrewsLD_LIBRARY_PATH_32=
c986916269e0d9ca0a31efb62ff5ac06938815dbTinderbox UserLD_LIBRARY_PATH_64=
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark AndrewsLD_PRELOAD=
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark AndrewsLD_PRELOAD_32=
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark AndrewsLD_PRELOAD_64=
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# Capture the current working directory so that we can change to it later.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# Then capture the location of this script and the Directory Server instance
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater# root so that we can use them to create appropriate paths.
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic UpdaterWORKING_DIR=`pwd`
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updatercd `dirname "${0}"`
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic UpdaterSCRIPT_DIR=`pwd`
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updatercd ..
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic UpdaterINSTANCE_ROOT=`pwd`
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updaterexport INSTANCE_ROOT
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updatercd "${WORKING_DIR}"
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater# Configure the appropriate CLASSPATH.
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic UpdaterCLASSPATH=${INSTANCE_ROOT}/classes
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updaterfor JAR in ${INSTANCE_ROOT}/lib/*.jar
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updaterdo
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater CLASSPATH=${CLASSPATH}:${JAR}
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updaterdone
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updaterexport CLASSPATH
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater
dba3c818ae00b10388d31703e86a28415db398acTinderbox User# See if any arguments were provided and if a local PID file exists. If there
43b94483957d3168796a816ed86cf097518817dcTinderbox User# were no arguments and there is a PID file, then try to stop the server with
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updater# a kill command.
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updaterif test -z "${1}"
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updaterthen
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater if test -f "${INSTANCE_ROOT}/logs/server.pid"
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater then
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater kill `cat "${INSTANCE_ROOT}/logs/server.pid"`
64affc54f96a2c71cbd10ed71e246ce0746259aaAutomatic Updater EXIT_CODE=${?}
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater if test "${EXIT_CODE}" -eq 0
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater then
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater "${JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater --logFile "${INSTANCE_ROOT}/logs/errors"
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater EXIT_CODE=${?}
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater fi
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater exit ${EXIT_CODE}
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater fi
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updaterfi
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews# If we've gotten here, then we should try to stop the server over LDAP.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews"${JAVA_BIN}" ${JAVA_ARGS} org.opends.server.tools.StopDS "${@}"
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews