stop-ds revision d319724fed3be916a9f68676aac6eb203d44b551
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore#!/bin/sh
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore#
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# CDDL HEADER START
21f450f4fd5fd60f951de44878aae015ed0342e3Adam Moore#
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# The contents of this file are subject to the terms of the
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Common Development and Distribution License, Version 1.0 only
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# (the "License"). You may not use this file except in compliance
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# with the License.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore#
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# You can obtain a copy of the license at
4f2de35716c5df46152747980516af484d0ab208Adam Moore# trunk/opends/resource/legal-notices/OpenDS.LICENSE
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
02fc09f797e83e80199c96adc4751c230dccc973Adam Moore# See the License for the specific language governing permissions
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# and limitations under the License.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore#
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# When distributing Covered Code, include this CDDL HEADER in each
5f8408be995d28c8f351f37fd05e7c8633fdea40Adam Moore# file and include the License file at
5f8408be995d28c8f351f37fd05e7c8633fdea40Adam Moore# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
5f8408be995d28c8f351f37fd05e7c8633fdea40Adam Moore# add the following below this CDDL HEADER, with the fields enclosed
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# by brackets "[]" replaced with your own identifying information:
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Portions Copyright [yyyy] [name of copyright owner]
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore#
c4f19796d319a7ec9a1e76d48adc82c9c5ae2f27Adam Moore# CDDL HEADER END
08e054017132cdd838955bc0af15889f1f2a7b42Adam Moore#
b46f3d670b654847b0ce60afdba1b461c492a5c9Adam Moore#
0dca577a07715960da42d47787eecc25b285182fAdam Moore# Copyright 2006-2008 Sun Microsystems, Inc.
b46f3d670b654847b0ce60afdba1b461c492a5c9Adam Moore
08e054017132cdd838955bc0af15889f1f2a7b42Adam Moore
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# This script may be used to request that the Directory Server shut down.
f647f9c7909e84a0b19f09de42ce82a715e2d52aAdam Moore# It operates in two different ways, depending on how it is invoked. If it
0771d781138a507b3e657573703f511291640bf3Adam Moore# is invoked without any arguments and a local PID file is available, then it
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# will stop the server by sending a TERM signal to the process, and this
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# script will wait until the server has stopped before exiting. If any
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# arguments were provided or there is no local PID file, then it will attempt
52671ce4f644d565b2acd71a8ce4f6d20829a67cAdam Moore# to stop the server using an LDAP request.
0771d781138a507b3e657573703f511291640bf3Adam Moore
0dca577a07715960da42d47787eecc25b285182fAdam Moore
9cdb1aa8d3a7901f789c2ad7a6ea00e804a9abebAdam Moore# Capture the current working directory so that we can change to it later.
0771d781138a507b3e657573703f511291640bf3Adam Moore# Then capture the location of this script and the Directory Server instance
0771d781138a507b3e657573703f511291640bf3Adam Moore# root so that we can use them to create appropriate paths.
0771d781138a507b3e657573703f511291640bf3Adam MooreWORKING_DIR=`pwd`
0771d781138a507b3e657573703f511291640bf3Adam Moore
9c42541e375e7bb70c53012b3012d70f1a380254Adam Moorecd "`dirname "${0}"`"
9c42541e375e7bb70c53012b3012d70f1a380254Adam MooreSCRIPT_DIR=`pwd`
9c42541e375e7bb70c53012b3012d70f1a380254Adam Moore
0771d781138a507b3e657573703f511291640bf3Adam Moorecd ..
9c42541e375e7bb70c53012b3012d70f1a380254Adam MooreINSTALL_ROOT=`pwd`
9c42541e375e7bb70c53012b3012d70f1a380254Adam Mooreexport INSTALL_ROOT
02fc09f797e83e80199c96adc4751c230dccc973Adam Moore
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moorecd "${WORKING_DIR}"
2690c090ce850e485d15cf691f59e8aaeb3b4bb1Adam Moore
8aa0880cd494c951e0f4aa7d82d8bdac7692c7d0Adam Moore# We keep this values to reset the environment before calling start-ds.
8aa0880cd494c951e0f4aa7d82d8bdac7692c7d0Adam MooreORIGINAL_JAVA_ARGS=${OPENDS_JAVA_ARGS}
8aa0880cd494c951e0f4aa7d82d8bdac7692c7d0Adam MooreORIGINAL_JAVA_HOME=${OPENDS_JAVA_HOME}
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam MooreORIGINAL_JAVA_BIN=${OPENDS_JAVA_BIN}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Specify the script name so that we can use the specified java properties.
80d2034f65b9348e5fd36291f03b0819181efb89Adam MooreSCRIPT_NAME="stop-ds"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Mooreexport SCRIPT_NAME
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Set environment variables
80d2034f65b9348e5fd36291f03b0819181efb89Adam MooreSCRIPT_UTIL_CMD=set-full-environment-and-test-java
2690c090ce850e485d15cf691f59e8aaeb3b4bb1Adam Mooreexport SCRIPT_UTIL_CMD
fb49666327c2cb6ea5a7d2dea5160b649bc07c51Adam Moore. "${INSTALL_ROOT}/lib/_script-util.sh"
2690c090ce850e485d15cf691f59e8aaeb3b4bb1Adam MooreRETURN_CODE=$?
80d2034f65b9348e5fd36291f03b0819181efb89Adam Mooreif test ${RETURN_CODE} -ne 0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moorethen
21f450f4fd5fd60f951de44878aae015ed0342e3Adam Moore exit ${RETURN_CODE}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moorefi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore"${OPENDS_JAVA_BIN}" ${OPENDS_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore org.opends.server.tools.StopDS --checkStoppability "${@}"
80d2034f65b9348e5fd36291f03b0819181efb89Adam MooreEC=${?}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore
80d2034f65b9348e5fd36291f03b0819181efb89Adam MooreSTOPPED=1
80d2034f65b9348e5fd36291f03b0819181efb89Adam MooreEXIT_CODE=1
80d2034f65b9348e5fd36291f03b0819181efb89Adam MooreMUST_START_USING_SYSTEM_CALL=1
80d2034f65b9348e5fd36291f03b0819181efb89Adam MooreMUST_STOP_USING_SYSTEM_CALL=1
80d2034f65b9348e5fd36291f03b0819181efb89Adam MooreQUIET_MODE=1
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore
80d2034f65b9348e5fd36291f03b0819181efb89Adam Mooreif test ${EC} -eq 98
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore#
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Already stopped and nothing else to do.
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore#
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moorethen
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore STOPPED=0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Mooreelse
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test ${EC} -eq 99 -o ${EC} -eq 105
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore #
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore # Already stopped and must start locally.
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore #
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore then
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore STOPPED=0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore MUST_START_USING_SYSTEM_CALL=0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test ${EC} -eq 105
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore then
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore QUIET_MODE=0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore else
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test ${EC} -eq 100
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore then
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore #
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore # Stop using system call
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore #
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore MUST_STOP_USING_SYSTEM_CALL=0
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore else
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore if test ${EC} -eq 101 -o ${EC} -eq 106
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore then
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore #
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore # Restart using system call
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore #
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore MUST_STOP_USING_SYSTEM_CALL=0
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore MUST_START_USING_SYSTEM_CALL=0
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore if test ${EC} -eq 106
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore then
eab87f0881fdf3e80c2a1af9224c50f0bf033644Adam Moore QUIET_MODE=0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore else
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test ${EC} -ne 102
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore then
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore exit ${EC}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moorefi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Mooreif test ${MUST_STOP_USING_SYSTEM_CALL} -eq 0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moorethen
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test -f "${INSTANCE_ROOT}/logs/server.pid"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore then
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore kill `cat "${INSTANCE_ROOT}/logs/server.pid"`
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore EXIT_CODE=${?}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test ${EXIT_CODE} -eq 0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore then
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore "${OPENDS_JAVA_BIN}" -Xms8M -Xmx8M org.opends.server.tools.WaitForFileDelete \
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore --logFile "${INSTANCE_ROOT}/logs/errors"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore EXIT_CODE=${?}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test ${EXIT_CODE} -eq 0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore then
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore STOPPED=0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore else
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore echo "ERROR: Unable to find the server.pid file to determine the process"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore echo " ID of the OpenDS process to terminate."
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore exit 1
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moorefi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Delete the pid file if the server is stopped (this can occur if the process
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# has been killed using kill -9).
80d2034f65b9348e5fd36291f03b0819181efb89Adam Mooreif test ${STOPPED} -eq 0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moorethen
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test -f "${INSTANCE_ROOT}/logs/server.pid"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore then
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore rm "${INSTANCE_ROOT}/logs/server.pid"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moorefi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Now if the user wants to restart the server, try to restart it if the server
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moore# is stopped.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Mooreif test ${MUST_START_USING_SYSTEM_CALL} -eq 0
abdfe7cf11d34f89f17b26e4779bf6079d22a910Adam Moorethen
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test ${STOPPED} -eq 0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore then
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Set the original values that the user had on the environment in order to be
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# sure that the start-ds script works with the proper arguments (in particular
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# if the user specified not to overwrite the environment).
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore OPENDS_JAVA_ARGS=${ORIGINAL_JAVA_ARGS}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore OPENDS_JAVA_HOME=${ORIGINAL_JAVA_HOME}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore OPENDS_JAVA_BIN=${ORIGINAL_JAVA_BIN}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test ${QUIET_MODE} -eq 0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore then
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore "${INSTALL_ROOT}/bin/start-ds" --quiet
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore EXIT_CODE=${?}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore exit ${EXIT_CODE}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore else
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore "${INSTALL_ROOT}/bin/start-ds"
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore EXIT_CODE=${?}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore exit ${EXIT_CODE}
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore fi
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore#
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# The user does not want to start the server locally and it is already stopped.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore# Just exit.
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore#
80d2034f65b9348e5fd36291f03b0819181efb89Adam Mooreelse
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore if test ${STOPPED} -eq 0
80d2034f65b9348e5fd36291f03b0819181efb89Adam Moore then
9bc9c1474a84983bd254adc2bc425c5b24d25526Adam Moore exit 0
9bc9c1474a84983bd254adc2bc425c5b24d25526Adam Moore fi
9bc9c1474a84983bd254adc2bc425c5b24d25526Adam Moorefi
9bc9c1474a84983bd254adc2bc425c5b24d25526Adam Moore
9bc9c1474a84983bd254adc2bc425c5b24d25526Adam Moore# If we've gotten here, then we should try to stop the server over LDAP.
9bc9c1474a84983bd254adc2bc425c5b24d25526Adam Moore"${OPENDS_JAVA_BIN}" ${JAVA_ARGS} ${SCRIPT_NAME_ARG} \
9bc9c1474a84983bd254adc2bc425c5b24d25526Adam Moore org.opends.server.tools.StopDS "${@}"
9c69eb57afb13ae0ffed8e442449f04922fe30adAdam Moore