stop-ds revision 266c5071a91fda6a5159b08ea8d45261228d03d5
9174efb969475801d0dc88eee35aae40c748d450nd#!/bin/sh
ec79b29695b183f794264bbb578c51e93d1f9b1emartin#
6aa2272cc4af77e605ba2c4a4781f8567408b7e3pquerna# CDDL HEADER START
ee508128c414648982d1cca7801f63b01a0a4f8aminfrin#
ff2e7b35704e8610383152ebc823b94515d9fc2eniq# The contents of this file are subject to the terms of the
ff2e7b35704e8610383152ebc823b94515d9fc2eniq# Common Development and Distribution License, Version 1.0 only
ff2e7b35704e8610383152ebc823b94515d9fc2eniq# (the "License"). You may not use this file except in compliance
ff2e7b35704e8610383152ebc823b94515d9fc2eniq# with the License.
0a44bb1ff02dc8d3623e919c6d59f151bdd92ea0ianh#
0a44bb1ff02dc8d3623e919c6d59f151bdd92ea0ianh# You can obtain a copy of the license at
52e3d2373288a4015d4152067c124e4dc9876f08trawick# trunk/opends/resource/legal-notices/OpenDS.LICENSE
52e3d2373288a4015d4152067c124e4dc9876f08trawick# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
52e3d2373288a4015d4152067c124e4dc9876f08trawick# See the License for the specific language governing permissions
6ecde05c829c9d0aa24b2b1c18b40c8739997571trawick# and limitations under the License.
6ecde05c829c9d0aa24b2b1c18b40c8739997571trawick#
6ecde05c829c9d0aa24b2b1c18b40c8739997571trawick# When distributing Covered Code, include this CDDL HEADER in each
17d53ea32c4968e47733f1c2c063ae07d280efd6jerenkrantz# file and include the License file at
17d53ea32c4968e47733f1c2c063ae07d280efd6jerenkrantz# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
17d53ea32c4968e47733f1c2c063ae07d280efd6jerenkrantz# add the following below this CDDL HEADER, with the fields enclosed
2d5532b13110a8d85653da92e97795b09cc25cc2trawick# by brackets "[]" replaced with your own identifying * information:
b38565306421ff53e9f7499bc728d6df5cec294dpquerna# Portions Copyright [yyyy] [name of copyright owner]
b38565306421ff53e9f7499bc728d6df5cec294dpquerna#
b38565306421ff53e9f7499bc728d6df5cec294dpquerna# CDDL HEADER END
b38565306421ff53e9f7499bc728d6df5cec294dpquerna#
3aeb30211790fef38a8297f990b7ad3b2c46ece9colm#
3aeb30211790fef38a8297f990b7ad3b2c46ece9colm# Portions Copyright 2006 Sun Microsystems, Inc.
9505e1a9012d92bfd2b6228e675156f44a27aa04colm
9505e1a9012d92bfd2b6228e675156f44a27aa04colm
3aeb30211790fef38a8297f990b7ad3b2c46ece9colm# This script may be used to request that the Directory Server shut down.
3aeb30211790fef38a8297f990b7ad3b2c46ece9colm# It operates in two different ways, depending on how it is invoked. If it
3aeb30211790fef38a8297f990b7ad3b2c46ece9colm# is invoked without any arguments and a local PID file is available, then it
3aeb30211790fef38a8297f990b7ad3b2c46ece9colm# will stop the server by sending a TERM signal to the process, and this
6eb3a057b5e4f046faba79104d7941552de755dacolm# script will wait until the server has stopped before exiting. If any
6eb3a057b5e4f046faba79104d7941552de755dacolm# arguments were provided or there is no local PID file, then it will attempt
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton# to stop the server using an LDAP request.
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton# See if JAVA_HOME is set. If not, then see if there is a java executable in
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton# the path and try to figure it out.
c07be90520f577cdffc0ee59a81e7f2be4ab24c6martinif test -z "${JAVA_BIN}"
2e02c854b4531480fe3f7ab353154c99c5bd97e8jortonthen
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton if test -z "${JAVA_HOME}"
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton then
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton JAVA_BIN=`which java 2> /dev/null`
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton if test ${?} -eq 0
6a9a6a63bae82591ea75fc602d5260109b8fa02ccolm then
70706a4d1ead0d72a443eac1cc446a0f1a4de069colm export JAVA_BIN
70706a4d1ead0d72a443eac1cc446a0f1a4de069colm else
70706a4d1ead0d72a443eac1cc446a0f1a4de069colm echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
70706a4d1ead0d72a443eac1cc446a0f1a4de069colm exit 1
70706a4d1ead0d72a443eac1cc446a0f1a4de069colm fi
9cfe09f7e922f7bdf61bfe10a47e8f25145cdf92colm else
9cfe09f7e922f7bdf61bfe10a47e8f25145cdf92colm JAVA_BIN=${JAVA_HOME}/bin/java
9cfe09f7e922f7bdf61bfe10a47e8f25145cdf92colm export JAVA_BIN
9cfe09f7e922f7bdf61bfe10a47e8f25145cdf92colm fi
2e02c854b4531480fe3f7ab353154c99c5bd97e8jortonfi
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
2e02c854b4531480fe3f7ab353154c99c5bd97e8jorton# system environment variables for security and compatibility reasons.
2e02c854b4531480fe3f7ab353154c99c5bd97e8jortonPATH=/bin:/usr/bin
2e02c854b4531480fe3f7ab353154c99c5bd97e8jortonLD_LIBRARY_PATH=
2e02c854b4531480fe3f7ab353154c99c5bd97e8jortonLD_LIBRARY_PATH_32=
a09378e32e823d5619f766394fcdde1cfa16c5dajimLD_LIBRARY_PATH_64=
a09378e32e823d5619f766394fcdde1cfa16c5dajimLD_PRELOAD=
a09378e32e823d5619f766394fcdde1cfa16c5dajimLD_PRELOAD_32=
a09378e32e823d5619f766394fcdde1cfa16c5dajimLD_PRELOAD_64=
a09378e32e823d5619f766394fcdde1cfa16c5dajimexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
a09378e32e823d5619f766394fcdde1cfa16c5dajim LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
a09378e32e823d5619f766394fcdde1cfa16c5dajim
ce8e09ffeb8c696f7fc6c5dfa8814c52caaac59bcolm
ce8e09ffeb8c696f7fc6c5dfa8814c52caaac59bcolm# Capture the current working directory so that we can change to it later.
ce8e09ffeb8c696f7fc6c5dfa8814c52caaac59bcolm# Then capture the location of this script and the Directory Server instance
ce8e09ffeb8c696f7fc6c5dfa8814c52caaac59bcolm# root so that we can use them to create appropriate paths.
5340bb8547e62ec8ede44b1b086b7da37ee64eefcolmWORKING_DIR=`pwd`
5340bb8547e62ec8ede44b1b086b7da37ee64eefcolm
5340bb8547e62ec8ede44b1b086b7da37ee64eefcolmcd `dirname "${0}"`
f6e71f622ffde40c654288851ff65b8505cf7596colmSCRIPT_DIR=`pwd`
f6e71f622ffde40c654288851ff65b8505cf7596colm
f6e71f622ffde40c654288851ff65b8505cf7596colmcd ..
f8ae06c7d0615d8b9441099794fe80a3f2915469colmINSTANCE_ROOT=`pwd`
f8ae06c7d0615d8b9441099794fe80a3f2915469colmexport INSTANCE_ROOT
f8ae06c7d0615d8b9441099794fe80a3f2915469colm
6eb3a057b5e4f046faba79104d7941552de755dacolmcd "${WORKING_DIR}"
6eb3a057b5e4f046faba79104d7941552de755dacolm
6eb3a057b5e4f046faba79104d7941552de755dacolm
6aa2272cc4af77e605ba2c4a4781f8567408b7e3pquerna# Configure the appropriate CLASSPATH.
6eb3a057b5e4f046faba79104d7941552de755dacolmCLASSPATH=${INSTANCE_ROOT}/classes
dface6840439ab84a36749f40e7773ebfdc2066ejortonfor JAR in ${INSTANCE_ROOT}/lib/*.jar
dface6840439ab84a36749f40e7773ebfdc2066ejortondo
dface6840439ab84a36749f40e7773ebfdc2066ejorton CLASSPATH=${CLASSPATH}:${JAR}
dface6840439ab84a36749f40e7773ebfdc2066ejortondone
dface6840439ab84a36749f40e7773ebfdc2066ejortonexport CLASSPATH
1febae173a82bc2a71c3c0ba4105cf674000791bjim
1febae173a82bc2a71c3c0ba4105cf674000791bjim
1febae173a82bc2a71c3c0ba4105cf674000791bjim# Specify the script name so that it may be provided in command-line usage.
1febae173a82bc2a71c3c0ba4105cf674000791bjimSCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=stop-ds"
1febae173a82bc2a71c3c0ba4105cf674000791bjimexport SCRIPT_NAME_ARG
2b409b0583ef844d6f85002160cbc6df95b9afa8jerenkrantz
2b409b0583ef844d6f85002160cbc6df95b9afa8jerenkrantz
2b409b0583ef844d6f85002160cbc6df95b9afa8jerenkrantz# See if any arguments were provided and if a local PID file exists. If there
2b409b0583ef844d6f85002160cbc6df95b9afa8jerenkrantz# were no arguments and there is a PID file, then try to stop the server with
454d060a0d7b13606978c536f632be71e311959djerenkrantz# a kill command.
454d060a0d7b13606978c536f632be71e311959djerenkrantzif test -z "${1}"
454d060a0d7b13606978c536f632be71e311959djerenkrantzthen
454d060a0d7b13606978c536f632be71e311959djerenkrantz if test -f "${INSTANCE_ROOT}/logs/server.pid"
1392b9997000dceb6aca39da0a1e6405ccb6f0a6jerenkrantz then
1392b9997000dceb6aca39da0a1e6405ccb6f0a6jerenkrantz kill `cat "${INSTANCE_ROOT}/logs/server.pid"`
1392b9997000dceb6aca39da0a1e6405ccb6f0a6jerenkrantz EXIT_CODE=${?}
4b0a0ae3fd77f8fc8fd2a693be33ffe4d99cb94ajerenkrantz if test "${EXIT_CODE}" -eq 0
4b0a0ae3fd77f8fc8fd2a693be33ffe4d99cb94ajerenkrantz then
4b0a0ae3fd77f8fc8fd2a693be33ffe4d99cb94ajerenkrantz "${JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
4b0a0ae3fd77f8fc8fd2a693be33ffe4d99cb94ajerenkrantz --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
4b0a0ae3fd77f8fc8fd2a693be33ffe4d99cb94ajerenkrantz --logFile "${INSTANCE_ROOT}/logs/errors"
4b0a0ae3fd77f8fc8fd2a693be33ffe4d99cb94ajerenkrantz EXIT_CODE=${?}
ee508128c414648982d1cca7801f63b01a0a4f8aminfrin fi
ee508128c414648982d1cca7801f63b01a0a4f8aminfrin exit ${EXIT_CODE}
ee508128c414648982d1cca7801f63b01a0a4f8aminfrin fi
ee508128c414648982d1cca7801f63b01a0a4f8aminfrinfi
f07ae092933846055c4ca046c5a65de83d79c9c6pquerna
f07ae092933846055c4ca046c5a65de83d79c9c6pquerna
f07ae092933846055c4ca046c5a65de83d79c9c6pquerna# If we've gotten here, then we should try to stop the server over LDAP.
9b88ec397b4155f3ff79bf7c08de5f15d21765b3pquerna"${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
9b88ec397b4155f3ff79bf7c08de5f15d21765b3pquerna org.opends.server.tools.StopDS "${@}"
9b88ec397b4155f3ff79bf7c08de5f15d21765b3pquerna