4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#!/bin/sh
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# CDDL HEADER START
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# The contents of this file are subject to the terms of the
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Common Development and Distribution License, Version 1.0 only
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# (the "License"). You may not use this file except in compliance
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# with the License.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac# You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac# or http://forgerock.org/license/CDDLv1.0.html.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# See the License for the specific language governing permissions
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# and limitations under the License.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# When distributing Covered Code, include this CDDL HEADER in each
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac# file and include the License file at legal-notices/CDDLv1_0.txt.
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac# If applicable, add the following below this CDDL HEADER, with the
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac# fields enclosed by brackets "[]" replaced with your own identifying
8cf870d281dc8c242f083d14dfef05f24aa5fceeJnRouvignac# information:
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# Portions Copyright [yyyy] [name of copyright owner]
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# CDDL HEADER END
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe#
6733dfd94dda39b3bce6e9fe9713d4d2379cbb85chebrard# Copyright 2006-2009 Sun Microsystems, Inc.
d3ce44d37110c284dad15122841fd97ee41d9ac5ludo# Portions Copyright 2011 ForgeRock AS
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# This script may be used to request that the Directory Server shut down.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# It operates in two different ways, depending on how it is invoked. If it
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# is invoked without any arguments and a local PID file is available, then it
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# will stop the server by sending a TERM signal to the process, and this
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# script will wait until the server has stopped before exiting. If any
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# arguments were provided or there is no local PID file, then it will attempt
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# to stop the server using an LDAP request.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson# Capture the current working directory so that we can change to it later.
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson# Then capture the location of this script and the Directory Server instance
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson# root so that we can use them to create appropriate paths.
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilsonWORKING_DIR=`pwd`
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson
3cedecd5ea21cca5d9709abf320a2082cd3694e5jvergaracd "`dirname "${0}"`"
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilsonSCRIPT_DIR=`pwd`
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilsoncd ..
014019918f7e3844f558f6159b8d41517254edc2lutoffINSTALL_ROOT=`pwd`
014019918f7e3844f558f6159b8d41517254edc2lutoffexport INSTALL_ROOT
014019918f7e3844f558f6159b8d41517254edc2lutoff
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilsoncd "${WORKING_DIR}"
69de0fe5b7ed905860bef5f86937d30cc206ef7dneil_a_wilson
7b94de75a19ac6d37a440a7915ae0c7b7c024527jvergara# We keep this values to reset the environment before calling start-ds.
0f8553e2af5fc49a510ecfcfc93e66d06713f631ludoORIGINAL_JAVA_ARGS=${OPENDJ_JAVA_ARGS}
0f8553e2af5fc49a510ecfcfc93e66d06713f631ludoORIGINAL_JAVA_HOME=${OPENDJ_JAVA_HOME}
0f8553e2af5fc49a510ecfcfc93e66d06713f631ludoORIGINAL_JAVA_BIN=${OPENDJ_JAVA_BIN}
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara# Specify the script name so that we can use the specified java properties.
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergaraSCRIPT_NAME="stop-ds"
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergaraexport SCRIPT_NAME
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
d3ce44d37110c284dad15122841fd97ee41d9ac5ludo# check for presence of lib/_svc-opendj.sh file
44a7ec1a853804826c90cda2fbb4ac712c86bbaaludovicp# If present, we should be on Solaris/OpenSolaris and use SMF to start
814920a099ee946453263e682c7bb2cda00b7983ludo# OpenDJ.
d3ce44d37110c284dad15122841fd97ee41d9ac5ludo# Check --exec. If not present, start OpenDJ from SMF
d3ce44d37110c284dad15122841fd97ee41d9ac5ludoif test -f "${INSTALL_ROOT}/lib/_svc-opendj.sh"
44a7ec1a853804826c90cda2fbb4ac712c86bbaaludovicpthen
2ed4722b4c052dcfe7884519a119e68a295f77afludovicp if [ "$1" = "--exec" ]
44a7ec1a853804826c90cda2fbb4ac712c86bbaaludovicp then
44a7ec1a853804826c90cda2fbb4ac712c86bbaaludovicp shift
44a7ec1a853804826c90cda2fbb4ac712c86bbaaludovicp elif [ "$1" != "-V" -a "$1" != "--version" -a "$1" != "-?" -a \
44a7ec1a853804826c90cda2fbb4ac712c86bbaaludovicp "$1" != "-H" -a "$1" != "--help" ]
44a7ec1a853804826c90cda2fbb4ac712c86bbaaludovicp#These options are not stopping the server, but checking version and help
44a7ec1a853804826c90cda2fbb4ac712c86bbaaludovicp then
6733dfd94dda39b3bce6e9fe9713d4d2379cbb85chebrard if [ "$1" = "-R" -o "$1" = "--restart" ]
6733dfd94dda39b3bce6e9fe9713d4d2379cbb85chebrard then
d3ce44d37110c284dad15122841fd97ee41d9ac5ludo /usr/sbin/svcadm disable -t svc:/network/ldap/server:opendj
6733dfd94dda39b3bce6e9fe9713d4d2379cbb85chebrard RETURN_CODE=$?
6733dfd94dda39b3bce6e9fe9713d4d2379cbb85chebrard if test ${RETURN_CODE} -ne 0
6733dfd94dda39b3bce6e9fe9713d4d2379cbb85chebrard then
6733dfd94dda39b3bce6e9fe9713d4d2379cbb85chebrard exit ${RETURN_CODE}
6733dfd94dda39b3bce6e9fe9713d4d2379cbb85chebrard fi
d3ce44d37110c284dad15122841fd97ee41d9ac5ludo exec /usr/sbin/svcadm enable -t svc:/network/ldap/server:opendj
6733dfd94dda39b3bce6e9fe9713d4d2379cbb85chebrard else
d3ce44d37110c284dad15122841fd97ee41d9ac5ludo exec /usr/sbin/svcadm disable -t svc:/network/ldap/server:opendj
6733dfd94dda39b3bce6e9fe9713d4d2379cbb85chebrard fi
44a7ec1a853804826c90cda2fbb4ac712c86bbaaludovicp fi
44a7ec1a853804826c90cda2fbb4ac712c86bbaaludovicpfi
44a7ec1a853804826c90cda2fbb4ac712c86bbaaludovicp
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara# Set environment variables
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergaraSCRIPT_UTIL_CMD=set-full-environment-and-test-java
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergaraexport SCRIPT_UTIL_CMD
014019918f7e3844f558f6159b8d41517254edc2lutoff. "${INSTALL_ROOT}/lib/_script-util.sh"
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergaraRETURN_CODE=$?
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergaraif test ${RETURN_CODE} -ne 0
39e085accf228684b9573bc8ad707a364ed6242ejvergarathen
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara exit ${RETURN_CODE}
39e085accf228684b9573bc8ad707a364ed6242ejvergarafi
266c5071a91fda6a5159b08ea8d45261228d03d5neil_a_wilson
27f8adec83293fb8bd3bfa37175322b0ee3bb933jvergara
0f8553e2af5fc49a510ecfcfc93e66d06713f631ludo"${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
7070667c2dffad87009999bdeb16d5305e0afdbejvergara org.opends.server.tools.StopDS --checkStoppability "${@}"
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraEC=${?}
7070667c2dffad87009999bdeb16d5305e0afdbejvergara
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraSTOPPED=1
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraEXIT_CODE=1
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraMUST_START_USING_SYSTEM_CALL=1
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraMUST_STOP_USING_SYSTEM_CALL=1
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilsonQUIET_MODE=1
7070667c2dffad87009999bdeb16d5305e0afdbejvergara
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraif test ${EC} -eq 98
7070667c2dffad87009999bdeb16d5305e0afdbejvergara#
7070667c2dffad87009999bdeb16d5305e0afdbejvergara# Already stopped and nothing else to do.
7070667c2dffad87009999bdeb16d5305e0afdbejvergara#
7070667c2dffad87009999bdeb16d5305e0afdbejvergarathen
7070667c2dffad87009999bdeb16d5305e0afdbejvergara STOPPED=0
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraelse
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson if test ${EC} -eq 99 -o ${EC} -eq 105
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
7070667c2dffad87009999bdeb16d5305e0afdbejvergara # Already stopped and must start locally.
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
f567e484335734979b8ff593b1f9357dd48d10f9jvergara then
7070667c2dffad87009999bdeb16d5305e0afdbejvergara STOPPED=0
7070667c2dffad87009999bdeb16d5305e0afdbejvergara MUST_START_USING_SYSTEM_CALL=0
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson if test ${EC} -eq 105
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson then
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson QUIET_MODE=0
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson fi
7070667c2dffad87009999bdeb16d5305e0afdbejvergara else
7070667c2dffad87009999bdeb16d5305e0afdbejvergara if test ${EC} -eq 100
f567e484335734979b8ff593b1f9357dd48d10f9jvergara then
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
7070667c2dffad87009999bdeb16d5305e0afdbejvergara # Stop using system call
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
7070667c2dffad87009999bdeb16d5305e0afdbejvergara MUST_STOP_USING_SYSTEM_CALL=0
f567e484335734979b8ff593b1f9357dd48d10f9jvergara else
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson if test ${EC} -eq 101 -o ${EC} -eq 106
7070667c2dffad87009999bdeb16d5305e0afdbejvergara then
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
7070667c2dffad87009999bdeb16d5305e0afdbejvergara # Restart using system call
7070667c2dffad87009999bdeb16d5305e0afdbejvergara #
7070667c2dffad87009999bdeb16d5305e0afdbejvergara MUST_STOP_USING_SYSTEM_CALL=0
7070667c2dffad87009999bdeb16d5305e0afdbejvergara MUST_START_USING_SYSTEM_CALL=0
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson if test ${EC} -eq 106
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson then
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson QUIET_MODE=0
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson fi
7070667c2dffad87009999bdeb16d5305e0afdbejvergara else
7070667c2dffad87009999bdeb16d5305e0afdbejvergara if test ${EC} -ne 102
7070667c2dffad87009999bdeb16d5305e0afdbejvergara then
7070667c2dffad87009999bdeb16d5305e0afdbejvergara exit ${EC}
7070667c2dffad87009999bdeb16d5305e0afdbejvergara fi
7070667c2dffad87009999bdeb16d5305e0afdbejvergara fi
f567e484335734979b8ff593b1f9357dd48d10f9jvergara fi
f567e484335734979b8ff593b1f9357dd48d10f9jvergara fi
7070667c2dffad87009999bdeb16d5305e0afdbejvergarafi
f567e484335734979b8ff593b1f9357dd48d10f9jvergara
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraif test ${MUST_STOP_USING_SYSTEM_CALL} -eq 0
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipethen
7070667c2dffad87009999bdeb16d5305e0afdbejvergara if test -f "${INSTANCE_ROOT}/logs/server.pid"
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
773465ac0ffcb0c5856718e21f59cdc671a99c4alutoff read PID < "${INSTANCE_ROOT}/logs/server.pid"
773465ac0ffcb0c5856718e21f59cdc671a99c4alutoff kill ${PID}
7070667c2dffad87009999bdeb16d5305e0afdbejvergara EXIT_CODE=${?}
7070667c2dffad87009999bdeb16d5305e0afdbejvergara if test ${EXIT_CODE} -eq 0
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe then
0f8553e2af5fc49a510ecfcfc93e66d06713f631ludo "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
7070667c2dffad87009999bdeb16d5305e0afdbejvergara --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
7070667c2dffad87009999bdeb16d5305e0afdbejvergara --logFile "${INSTANCE_ROOT}/logs/errors"
7070667c2dffad87009999bdeb16d5305e0afdbejvergara EXIT_CODE=${?}
7070667c2dffad87009999bdeb16d5305e0afdbejvergara if test ${EXIT_CODE} -eq 0
7070667c2dffad87009999bdeb16d5305e0afdbejvergara then
7070667c2dffad87009999bdeb16d5305e0afdbejvergara STOPPED=0
7070667c2dffad87009999bdeb16d5305e0afdbejvergara fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe fi
86580987a3bc88a2018319660f3b536c381938f5neil_a_wilson else
86580987a3bc88a2018319660f3b536c381938f5neil_a_wilson echo "ERROR: Unable to find the server.pid file to determine the process"
814920a099ee946453263e682c7bb2cda00b7983ludo echo " ID of the OpenDJ process to terminate."
86580987a3bc88a2018319660f3b536c381938f5neil_a_wilson exit 1
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe fi
7070667c2dffad87009999bdeb16d5305e0afdbejvergarafi
7070667c2dffad87009999bdeb16d5305e0afdbejvergara
7070667c2dffad87009999bdeb16d5305e0afdbejvergara# Delete the pid file if the server is stopped (this can occur if the process
7070667c2dffad87009999bdeb16d5305e0afdbejvergara# has been killed using kill -9).
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraif test ${STOPPED} -eq 0
7070667c2dffad87009999bdeb16d5305e0afdbejvergarathen
7070667c2dffad87009999bdeb16d5305e0afdbejvergara if test -f "${INSTANCE_ROOT}/logs/server.pid"
dde4e18690d219fc5aa41b62d3090ce8b2bbb1d7jvergara then
7070667c2dffad87009999bdeb16d5305e0afdbejvergara rm "${INSTANCE_ROOT}/logs/server.pid"
dde4e18690d219fc5aa41b62d3090ce8b2bbb1d7jvergara fi
7070667c2dffad87009999bdeb16d5305e0afdbejvergarafi
814920a099ee946453263e682c7bb2cda00b7983ludo
7070667c2dffad87009999bdeb16d5305e0afdbejvergara# Now if the user wants to restart the server, try to restart it if the server
7070667c2dffad87009999bdeb16d5305e0afdbejvergara# is stopped.
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraif test ${MUST_START_USING_SYSTEM_CALL} -eq 0
7070667c2dffad87009999bdeb16d5305e0afdbejvergarathen
7070667c2dffad87009999bdeb16d5305e0afdbejvergara if test ${STOPPED} -eq 0
dde4e18690d219fc5aa41b62d3090ce8b2bbb1d7jvergara then
7b94de75a19ac6d37a440a7915ae0c7b7c024527jvergara# Set the original values that the user had on the environment in order to be
7b94de75a19ac6d37a440a7915ae0c7b7c024527jvergara# sure that the start-ds script works with the proper arguments (in particular
7b94de75a19ac6d37a440a7915ae0c7b7c024527jvergara# if the user specified not to overwrite the environment).
0f8553e2af5fc49a510ecfcfc93e66d06713f631ludo OPENDJ_JAVA_ARGS=${ORIGINAL_JAVA_ARGS}
0f8553e2af5fc49a510ecfcfc93e66d06713f631ludo OPENDJ_JAVA_HOME=${ORIGINAL_JAVA_HOME}
0f8553e2af5fc49a510ecfcfc93e66d06713f631ludo OPENDJ_JAVA_BIN=${ORIGINAL_JAVA_BIN}
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson if test ${QUIET_MODE} -eq 0
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson then
014019918f7e3844f558f6159b8d41517254edc2lutoff "${INSTALL_ROOT}/bin/start-ds" --quiet
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson EXIT_CODE=${?}
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson exit ${EXIT_CODE}
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson else
014019918f7e3844f558f6159b8d41517254edc2lutoff "${INSTALL_ROOT}/bin/start-ds"
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson EXIT_CODE=${?}
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson exit ${EXIT_CODE}
61ae414d98d24ba4a72a905b07db9424353669f4neil_a_wilson fi
7070667c2dffad87009999bdeb16d5305e0afdbejvergara fi
7070667c2dffad87009999bdeb16d5305e0afdbejvergara#
7070667c2dffad87009999bdeb16d5305e0afdbejvergara# The user does not want to start the server locally and it is already stopped.
7070667c2dffad87009999bdeb16d5305e0afdbejvergara# Just exit.
7070667c2dffad87009999bdeb16d5305e0afdbejvergara#
7070667c2dffad87009999bdeb16d5305e0afdbejvergaraelse
7070667c2dffad87009999bdeb16d5305e0afdbejvergara if test ${STOPPED} -eq 0
7070667c2dffad87009999bdeb16d5305e0afdbejvergara then
7070667c2dffad87009999bdeb16d5305e0afdbejvergara exit 0
dde4e18690d219fc5aa41b62d3090ce8b2bbb1d7jvergara fi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipefi
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe# If we've gotten here, then we should try to stop the server over LDAP.
0f8553e2af5fc49a510ecfcfc93e66d06713f631ludo"${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
7070667c2dffad87009999bdeb16d5305e0afdbejvergara org.opends.server.tools.StopDS "${@}"