stop-ds revision 873
d657c51f14601d0235434ffb78cf6ac0f27cc83cLennart Poettering#!/bin/sh
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering#
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# CDDL HEADER START
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering#
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# The contents of this file are subject to the terms of the
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# Common Development and Distribution License, Version 1.0 only
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# (the "License"). You may not use this file except in compliance
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# with the License.
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering#
9fa2f41077b2d76685058836f602f38715b5eef3Kay Sievers# You can obtain a copy of the license at
9fa2f41077b2d76685058836f602f38715b5eef3Kay Sievers# trunk/opends/resource/legal-notices/OpenDS.LICENSE
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# See the License for the specific language governing permissions
9fa2f41077b2d76685058836f602f38715b5eef3Kay Sievers# and limitations under the License.
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering#
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# When distributing Covered Code, include this CDDL HEADER in each
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# file and include the License file at
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# add the following below this CDDL HEADER, with the fields enclosed
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# by brackets "[]" replaced with your own identifying information:
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# Portions Copyright [yyyy] [name of copyright owner]
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering#
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# CDDL HEADER END
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering#
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering#
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# Portions Copyright 2006-2007 Sun Microsystems, Inc.
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering# This script may be used to request that the Directory Server shut down.
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering# It operates in two different ways, depending on how it is invoked. If it
673eab9bf0d2d79a72f3d7c430807b8786de7ee3Lennart Poettering# is invoked without any arguments and a local PID file is available, then it
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering# will stop the server by sending a TERM signal to the process, and this
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering# script will wait until the server has stopped before exiting. If any
7c09aafd269bc04dcfc07d94c4ee583b7b0751e6Kay Sievers# arguments were provided or there is no local PID file, then it will attempt
673eab9bf0d2d79a72f3d7c430807b8786de7ee3Lennart Poettering# to stop the server using an LDAP request.
31cee6f634ce07aa2c3514a506f93830f91f14a5Lennart Poettering
b7f44df59a7f76d2bd5302df2f5ec9be9b7fa2faLennart Poettering
b7f44df59a7f76d2bd5302df2f5ec9be9b7fa2faLennart Poettering# Capture the current working directory so that we can change to it later.
b7f44df59a7f76d2bd5302df2f5ec9be9b7fa2faLennart Poettering# Then capture the location of this script and the Directory Server instance
b7f44df59a7f76d2bd5302df2f5ec9be9b7fa2faLennart Poettering# root so that we can use them to create appropriate paths.
c1c8ca815bb1ef040c0a84cccd51282e4ce8f4deKay SieversWORKING_DIR=`pwd`
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poettering
e30431623a7d871da123cc37055ac49abf2c20eaTom Gundersencd `dirname "${0}"`
e30431623a7d871da123cc37055ac49abf2c20eaTom GundersenSCRIPT_DIR=`pwd`
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poettering
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poetteringcd ..
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart PoetteringINSTANCE_ROOT=`pwd`
19d5d4cb6a89c844e298eb65bce6ba0fa9d58b91Zbigniew Jędrzejewski-Szmekexport INSTANCE_ROOT
fb0951b02ebf51a93acf12721d8857d31ce57ba3Lennart Poettering
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poetteringcd "${WORKING_DIR}"
19d5d4cb6a89c844e298eb65bce6ba0fa9d58b91Zbigniew Jędrzejewski-Szmek
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poettering
7b17a7d72f5ba5ad838b19803534c56a46f3bce9Lennart Poettering# See if JAVA_HOME is set. If not, then see if there is a java executable in
7b17a7d72f5ba5ad838b19803534c56a46f3bce9Lennart Poettering# the path and try to figure it out.
7b17a7d72f5ba5ad838b19803534c56a46f3bce9Lennart Poetteringif test -z "${JAVA_BIN}"
2cc86f094a8c316f7feb0336df3827a3264b116dZbigniew Jędrzejewski-Szmekthen
2cc86f094a8c316f7feb0336df3827a3264b116dZbigniew Jędrzejewski-Szmek if test -z "${JAVA_HOME}"
2cc86f094a8c316f7feb0336df3827a3264b116dZbigniew Jędrzejewski-Szmek then
2cc86f094a8c316f7feb0336df3827a3264b116dZbigniew Jędrzejewski-Szmek if test -f "${INSTANCE_ROOT}/bin/set-java-home"
2cc86f094a8c316f7feb0336df3827a3264b116dZbigniew Jędrzejewski-Szmek then
c3d2d86d4f40593a361e33b101f5384a8ea2cdb7Tom Gundersen . "${INSTANCE_ROOT}/bin/set-java-home"
c3d2d86d4f40593a361e33b101f5384a8ea2cdb7Tom Gundersen JAVA_BIN="${JAVA_HOME}/bin/java"
2cc86f094a8c316f7feb0336df3827a3264b116dZbigniew Jędrzejewski-Szmek export JAVA_BIN
46ba8aae2b82bc5c87ba347e6bf914ecd5e9d51eLennart Poettering else
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poettering JAVA_BIN=`which java 2> /dev/null`
f1c24fea94e19cf2108abbeed1d36ded7102ab98Zbigniew Jędrzejewski-Szmek if test ${?} -eq 0
f1c24fea94e19cf2108abbeed1d36ded7102ab98Zbigniew Jędrzejewski-Szmek then
f1c24fea94e19cf2108abbeed1d36ded7102ab98Zbigniew Jędrzejewski-Szmek export JAVA_BIN
f1c24fea94e19cf2108abbeed1d36ded7102ab98Zbigniew Jędrzejewski-Szmek else
f1c24fea94e19cf2108abbeed1d36ded7102ab98Zbigniew Jędrzejewski-Szmek echo "Please set JAVA_HOME to the root of a Java 5.0 installation."
f1c24fea94e19cf2108abbeed1d36ded7102ab98Zbigniew Jędrzejewski-Szmek exit 1
f1c24fea94e19cf2108abbeed1d36ded7102ab98Zbigniew Jędrzejewski-Szmek fi
2cc86f094a8c316f7feb0336df3827a3264b116dZbigniew Jędrzejewski-Szmek fi
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poettering else
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poettering JAVA_BIN="${JAVA_HOME}/bin/java"
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poettering export JAVA_BIN
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poettering fi
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poetteringfi
3ede835a0486f2ecc025dede0b33e9a1edc06d30Lennart Poettering
19d5d4cb6a89c844e298eb65bce6ba0fa9d58b91Zbigniew Jędrzejewski-Szmek
b62cfcea00862ccbf0e5e297f8a339f70987edefMichael Biebl# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
19d5d4cb6a89c844e298eb65bce6ba0fa9d58b91Zbigniew Jędrzejewski-Szmek# system environment variables for security and compatibility reasons.
19d5d4cb6a89c844e298eb65bce6ba0fa9d58b91Zbigniew Jędrzejewski-SzmekPATH=/bin:/usr/bin
9015fa646e04fc3cb180bea24c33d34edbb48ed7Zbigniew Jędrzejewski-SzmekLD_LIBRARY_PATH=
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart PoetteringLD_LIBRARY_PATH_32=
fff2e5b58bab7a5ffbb7593742d462197b06728cLennart PoetteringLD_LIBRARY_PATH_64=
fff2e5b58bab7a5ffbb7593742d462197b06728cLennart PoetteringLD_PRELOAD=
edca2e2348b314e2d892fe6f8ae276fdc223f014Thomas Hindoe Paaboel AndersenLD_PRELOAD_32=
fff2e5b58bab7a5ffbb7593742d462197b06728cLennart PoetteringLD_PRELOAD_64=
bf9e477c92506884977d6c8d761969e105528f3eKay Sieversexport PATH LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64 \
fff2e5b58bab7a5ffbb7593742d462197b06728cLennart Poettering LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_34
6705c2df468a6afb4f8f834822780add123065e2Lennart Poettering
49f43d5f91a99b23f745726aa351d8f159774357Ville Skyttä
6705c2df468a6afb4f8f834822780add123065e2Lennart Poettering# Configure the appropriate CLASSPATH.
6705c2df468a6afb4f8f834822780add123065e2Lennart PoetteringCLASSPATH=${INSTANCE_ROOT}/classes
6705c2df468a6afb4f8f834822780add123065e2Lennart Poetteringfor JAR in ${INSTANCE_ROOT}/lib/*.jar
9015fa646e04fc3cb180bea24c33d34edbb48ed7Zbigniew Jędrzejewski-Szmekdo
9015fa646e04fc3cb180bea24c33d34edbb48ed7Zbigniew Jędrzejewski-Szmek CLASSPATH=${CLASSPATH}:${JAR}
9015fa646e04fc3cb180bea24c33d34edbb48ed7Zbigniew Jędrzejewski-Szmekdone
9015fa646e04fc3cb180bea24c33d34edbb48ed7Zbigniew Jędrzejewski-Szmekexport CLASSPATH
9015fa646e04fc3cb180bea24c33d34edbb48ed7Zbigniew Jędrzejewski-Szmek
9015fa646e04fc3cb180bea24c33d34edbb48ed7Zbigniew Jędrzejewski-Szmek
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart Poettering# Specify the script name so that it may be provided in command-line usage.
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart PoetteringSCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=stop-ds"
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart Poetteringexport SCRIPT_NAME_ARG
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart Poettering
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart Poettering
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart Poettering# If there were no arguments (or only the -R argument was passed) we assume that
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart Poettering# the server to be stopped is the local server. If this is the case we check if
ed1c99fcc13f279eccf25fc20427eb92867da245Lennart Poettering# the server is running or not.
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart Poettering# If the server is running then try to stop the server with a kill command. If
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart Poettering# there are more arguments, try to stop the server using LDAP protocol.
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart PoetteringNO_ARG_OR_ONLY_RESTART=1
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart PoetteringRESTART=0
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart Poetteringfor ARG in "${@}"
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart Poetteringdo
21bc923aa35d455cdef1607eb7022608c705c9f3Lennart Poettering if test "${ARG}" != "-R"
fc7a744cc44cdb80bf9bc6304fc3f80ca2cb65f9Lennart Poettering then
aa1671320df5bd8aa4108c0efb34a49fdedd0e5fLennart Poettering if test "${ARG}" != "--restart"
aa1671320df5bd8aa4108c0efb34a49fdedd0e5fLennart Poettering then
aa1671320df5bd8aa4108c0efb34a49fdedd0e5fLennart Poettering NO_ARG_OR_ONLY_RESTART=0
1b4bb4fdac4dce4e658aa3743153d77c04d1a331Zbigniew Jędrzejewski-Szmek else
1b4bb4fdac4dce4e658aa3743153d77c04d1a331Zbigniew Jędrzejewski-Szmek RESTART=1
1b4bb4fdac4dce4e658aa3743153d77c04d1a331Zbigniew Jędrzejewski-Szmek fi
1b4bb4fdac4dce4e658aa3743153d77c04d1a331Zbigniew Jędrzejewski-Szmek else
1b4bb4fdac4dce4e658aa3743153d77c04d1a331Zbigniew Jędrzejewski-Szmek RESTART=1
fc7a744cc44cdb80bf9bc6304fc3f80ca2cb65f9Lennart Poettering fi
fc7a744cc44cdb80bf9bc6304fc3f80ca2cb65f9Lennart Poetteringdone
fc7a744cc44cdb80bf9bc6304fc3f80ca2cb65f9Lennart Poettering
fc7a744cc44cdb80bf9bc6304fc3f80ca2cb65f9Lennart Poetteringif test ${NO_ARG_OR_ONLY_RESTART} -eq 1
fc7a744cc44cdb80bf9bc6304fc3f80ca2cb65f9Lennart Poetteringthen
fc7a744cc44cdb80bf9bc6304fc3f80ca2cb65f9Lennart Poettering # Use the code in StopDS class to know if the server is already
fc7a744cc44cdb80bf9bc6304fc3f80ca2cb65f9Lennart Poettering # stopped. An exit code of 99 means that the server is stopped.
fc7a744cc44cdb80bf9bc6304fc3f80ca2cb65f9Lennart Poettering STOPPED=0
fc7a744cc44cdb80bf9bc6304fc3f80ca2cb65f9Lennart Poettering "${JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
org.opends.server.tools.StopDS --checkStoppability
EC=${?}
if test ${EC} -ne 99
then
STOPPED=1
fi
EXIT_CODE=0
if test "${STOPPED}" -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 "${EXIT_CODE}" -eq 0
then
STOPPED=0
fi
fi
fi
fi
# Delete the pid file if the server is stopped (this can occur if the process has
# been killed using kill -9).
if test "{$STOPPED}" -eq 0
then
if test -f "${INSTANCE_ROOT}/logs/server.pid"
then
rm "${INSTANCE_ROOT}/logs/server.pid"
fi
fi
# Now if the user wants to restart the server, try to restart it if the server
# is stopped.
if test "${RESTART}" -eq 1
then
if test "${STOPPED}" -eq 0
then
"${INSTANCE_ROOT}/bin/start-ds"
EXIT_CODE=${?}
fi
fi
exit ${EXIT_CODE}
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 "${@}"