6331N/A#!/bin/ksh93
6331N/A#
6331N/A# $Id: stop-ds 553 2013-04-13 17:41:34Z elkner $
486N/A#
486N/A# CDDL HEADER START
486N/A#
486N/A# The contents of this file are subject to the terms of the
486N/A# Common Development and Distribution License, Version 1.0 only
486N/A# (the "License"). You may not use this file except in compliance
486N/A# with the License.
486N/A#
486N/A# You can obtain a copy of the license at
486N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE
486N/A# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
486N/A# See the License for the specific language governing permissions
486N/A# and limitations under the License.
486N/A#
486N/A# When distributing Covered Code, include this CDDL HEADER in each
486N/A# file and include the License file at
486N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
486N/A# add the following below this CDDL HEADER, with the fields enclosed
873N/A# by brackets "[]" replaced with your own identifying information:
486N/A# Portions Copyright [yyyy] [name of copyright owner]
486N/A#
486N/A# CDDL HEADER END
486N/A#
486N/A#
4103N/A# Copyright 2006-2009 Sun Microsystems, Inc.
5306N/A# Portions Copyright 2011 ForgeRock AS
6331N/A# Portions Copyright 2013 Jens Elkner
486N/A
486N/A# This script may be used to request that the Directory Server shut down.
486N/A# It operates in two different ways, depending on how it is invoked. If it
486N/A# is invoked without any arguments and a local PID file is available, then it
486N/A# will stop the server by sending a TERM signal to the process, and this
486N/A# script will wait until the server has stopped before exiting. If any
486N/A# arguments were provided or there is no local PID file, then it will attempt
486N/A# to stop the server using an LDAP request.
486N/A
6331N/AINSTALL_ROOT="${.sh.file%/*/*}" SCRIPT_NAME='stop-ds'
619N/A
3196N/A# We keep this values to reset the environment before calling start-ds.
5636N/AORIGINAL_JAVA_ARGS=${OPENDJ_JAVA_ARGS}
5636N/AORIGINAL_JAVA_HOME=${OPENDJ_JAVA_HOME}
5636N/AORIGINAL_JAVA_BIN=${OPENDJ_JAVA_BIN}
486N/A
6331N/A# Set environment variables
6331N/A. "${INSTALL_ROOT}"/lib/_script-util.sh
6331N/AcheckEnv -i 'set-full-environment-and-test-java' "$@"
486N/A
6331N/Aif ! isVersionOrHelp "$@" ; then
6331N/A integer RESTART=0
6331N/A for ARG in "$@" ; do
6331N/A [[ ${ARG} == '-R' || ${ARG} == '--restart' ]] && RESTART=1 && break
6331N/A done
6331N/A # If restart is requested, check whether the service is not disabled. If so,
6331N/A # use svcadm to restart, otherwise fall through.
6331N/A if (( ${RESTART} )) && [[ -n "${SMF_FMRI}" && ${ uname -s ; } == 'SunOS' ]]
6331N/A then
6331N/A STATE=${ svcs -H -o state ${SMF_FMRI} 2>/dev/null ; }
6331N/A if [[ -n ${STATE} && ${STATE} != 'disabled' ]]; then
6331N/A TARG=${ svcprop -p general_ovr/enabled ${SMF_FMRI} 2>/dev/null ; }
6331N/A [[ ${TARG} == 'true' ]] && TARG='-t' || TARG=''
6331N/A print -u2 "Restarting service '${SMF_FMRI}' ..."
6331N/A /usr/sbin/svcadm disable -s ${SMF_FMRI} || exit $?
6331N/A /usr/sbin/svcadm enable -s ${TARG} ${SMF_FMRI}
6331N/A RC=$?
6331N/A (( ${RC} != 0 )) && print -u2 'Done.' || print -u2 'Failed.'
6331N/A exit ${RC}
6331N/A fi
6331N/A fi
3972N/Afi
3972N/A
5636N/A"${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
6331N/A org.opends.server.tools.StopDS --checkStoppability "$@"
6331N/ARC=$?
832N/A
961N/ASTOPPED=1
961N/AEXIT_CODE=1
961N/AMUST_START_USING_SYSTEM_CALL=1
961N/AMUST_STOP_USING_SYSTEM_CALL=1
2296N/AQUIET_MODE=1
961N/A
6331N/Aif (( ${RC} == 98 )); then
6331N/A # Already stopped and nothing else to do.
6331N/A STOPPED=0
6331N/Aelif (( ${RC} == 99 || ${RC} == 105 )); then
6331N/A # Already stopped and must start locally
6331N/A STOPPED=0
6331N/A MUST_START_USING_SYSTEM_CALL=0
6331N/A (( ${RC} == 105 )) && QUIET_MODE=0
6331N/Aelif (( ${RC} == 100 )); then
6331N/A # Stop using system call
6331N/A MUST_STOP_USING_SYSTEM_CALL=0
6331N/Aelif (( ${RC} == 101 || ${RC} == 106 )); then
6331N/A # Restart using system call
6331N/A MUST_STOP_USING_SYSTEM_CALL=0
6331N/A MUST_START_USING_SYSTEM_CALL=0
6331N/A (( ${RC} == 106 )) && QUIET_MODE=0
6331N/Aelif (( ${RC} != 102 )); then
6331N/A # If != stop using protocol
6331N/A exit ${RC}
961N/Afi
961N/A
6331N/Aif (( ${MUST_STOP_USING_SYSTEM_CALL} == 0 )); then
6331N/A if [[ ! -f ${INSTANCE_ROOT}/logs/server.pid ]]; then
6331N/A print -u2 'ERROR: Unable to find the server.pid file to determine' \
6331N/A 'the process ID of the OpenDJ process to terminate.'
6331N/A exit 1
6331N/A fi
6331N/A PID=$(< "${INSTANCE_ROOT}"/logs/server.pid)
6331N/A kill $PID
6331N/A if (( $? == 0 )) ; then
6331N/A "${OPENDJ_JAVA_BIN}" \
6331N/A -client org.opends.server.tools.WaitForFileDelete \
6331N/A --targetFile "${INSTANCE_ROOT}"/logs/server.pid \
6331N/A --logFile "${INSTANCE_ROOT}"/logs/errors
6331N/A (( $? == 0 )) && STOPPED=0
6331N/A fi
486N/Afi
486N/A
961N/A# Delete the pid file if the server is stopped (this can occur if the process
961N/A# has been killed using kill -9).
6331N/A(( ${STOPPED} == 0 )) && [[ -f ${INSTANCE_ROOT}/logs/server.pid ]] && \
6331N/A rm "${INSTANCE_ROOT}"/logs/server.pid
5612N/A
961N/A# Now if the user wants to restart the server, try to restart it if the server
961N/A# is stopped.
6331N/Aif (( ${MUST_START_USING_SYSTEM_CALL} == 0 && ${STOPPED} == 0 )); then
6331N/A # Set the original values that the user had on the environment in order
6331N/A # to be sure that the start-ds script works with the proper arguments
6331N/A # (in particular if the user specified not to overwrite the environment)
6331N/A OPENDJ_JAVA_ARGS=${ORIGINAL_JAVA_ARGS}
6331N/A OPENDJ_JAVA_HOME=${ORIGINAL_JAVA_HOME}
6331N/A OPENDJ_JAVA_BIN=${ORIGINAL_JAVA_BIN}
6331N/A (( ${QUIET_MODE} == 0 )) && QUIET='--quiet' || QUIET=''
6331N/A "${INSTALL_ROOT}"/bin/start-ds ${QUIET}
6331N/A exit $?
6331N/Afi
6331N/A
961N/A# The user does not want to start the server locally and it is already stopped.
961N/A# Just exit.
6331N/A(( ${STOPPED} == 0 )) && exit 0
486N/A
486N/A# If we've gotten here, then we should try to stop the server over LDAP.
5636N/A"${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
6331N/A -Dorg.opends.server.InstallRoot="${INSTALL_ROOT}" \
6331N/A -Dorg.opends.server.InstanceRoot="${INSTANCE_ROOT}" \
6331N/A org.opends.server.tools.StopDS "$@"