6331N/A#!/bin/ksh93
6331N/A#
6331N/A# $Id: start-ds 560 2013-05-22 07:36: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#
4362N/A# Copyright 2006-2009 Sun Microsystems, Inc.
6331N/A# Portions Copyright 2011 ForgeRock AS
6331N/A# Portions Copyright 2013 Jens Elkner
486N/A
6331N/AINSTALL_ROOT="${.sh.file%/*/*}" SCRIPT_NAME='start-ds'
3972N/A
2976N/A# Set environment variables
6331N/ACHECK_VERSION='yes'
6331N/A. "${INSTALL_ROOT}"/lib/_script-util.sh
6331N/A# would use -i, but -s is also just version info but is not a common switch
6331N/AcheckEnv 'set-full-environment-and-test-java'
6331N/A
6331N/Ainteger QUIET=0 DETACH=1 INFO=0
6331N/Atypeset -a DJARGS=( )
6331N/Aif isVersionOrHelp "$@" ; then
6331N/A INFO=1
6331N/Aelse
6331N/A if [[ ${ LC_ALL= LC_MESSAGES=C tty ; } == 'not a tty' ]]; then
6331N/A # remove no detach arg and assume, it is started by SMF
6331N/A for ARG in "$@" ; do
6331N/A [[ ${ARG} == '-N' || ${ARG} == '--nodetach' ]] && continue
6331N/A [[ ${ARG} == '-Q' || ${ARG} == '--quiet' ]] && QUIET=1
6331N/A [[ ${ARG} == '-F' || ${ARG} == '--fullVersion' ]] && INFO=1
6331N/A [[ ${ARG} == '-s' || ${ARG} == '--systemInfo' ]] && INFO=1
6331N/A DJARGS+=( "${ARG}" )
6331N/A done
6331N/A else
6331N/A for ARG in "$@" ; do
6331N/A [[ ${ARG} == '-N' || ${ARG} == '--nodetach' ]] && DETACH=0
6331N/A [[ ${ARG} == '-Q' || ${ARG} == '--quiet' ]] && QUIET=1
6331N/A [[ ${ARG} == '-F' || ${ARG} == '--fullVersion' ]] && INFO=1
6331N/A [[ ${ARG} == '-s' || ${ARG} == '--systemInfo' ]] && INFO=1
6331N/A DJARGS+=( "${ARG}" )
6331N/A done
6331N/A # issue a warning, if the service is running and one tries to start it
6331N/A # manually as well - let the app do the rest
6331N/A if (( ! INFO )) && [[ ${ uname -s ; } == 'SunOS' ]]; then
6331N/A STATE=''
6331N/A [[ -n ${SMF_FMRI} ]] && \
6331N/A STATE=${ svcs -H -o state ${SMF_FMRI} 2>/dev/null; }
6331N/A if [[ -n ${STATE} && ${STATE} != 'disabled' ]]; then
6331N/A print -u2 "WARNING: The service '${SMF_FMRI}' is not disabled!"
6331N/A fi
6331N/A fi
6331N/A fi
1181N/Afi
536N/A
3860N/A# Specify the locations of important files that may be used when the server
3860N/A# is starting.
6331N/ACONFIG_FILE="${INSTANCE_ROOT}"/config/config.ldif
6331N/APID_FILE="${INSTANCE_ROOT}"/logs/server.pid
6331N/ALOG_FILE="${INSTANCE_ROOT}"/logs/server.out
6331N/ASTARTING_FILE="${INSTANCE_ROOT}"/logs/server.starting
6331N/A
6331N/Aif (( ${INFO} )); then
6331N/A "${OPENDJ_JAVA_BIN}" -client ${SCRIPT_NAME_ARG} \
6331N/A -Dorg.opends.server.InstallRoot="${INSTALL_ROOT}" \
6331N/A -Dorg.opends.server.InstanceRoot="${INSTANCE_ROOT}" \
6331N/A org.opends.server.core.DirectoryServer \
6331N/A --configClass org.opends.server.extensions.ConfigFileHandler \
6331N/A --configFile "${CONFIG_FILE}" "$@"
6331N/A exit $?
6331N/Afi
6331N/AcheckInstanceDir
3860N/A
6331N/A# We do not check for startability, since for non-Windows it just returns
6331N/A# based on the passed arguments:
6331N/A# 99 => 'start as detached'
6331N/A# 100 => 'start as non-detached'
6331N/A# 103 => 'start as detached quiet'
6331N/A# 104 => 'start as non-detached quiet'
6331N/A# what we already know by parsing the args above. If an arg or instance problem
6331N/A# exists, exit 999 from checkEnv or checkInstance would prevent getting here.
6331N/A# So doing a --checkStartability would not by us anything ...
6331N/A
6331N/Aif (( ${DETACH} )); then
6331N/A touch "${STARTING_FILE}"
6331N/A nohup "${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.core.DirectoryServer \
6331N/A --configClass org.opends.server.extensions.ConfigFileHandler \
6331N/A --configFile "${CONFIG_FILE}" "${DJARGS[@]}" > "${LOG_FILE}" 2>&1 &
6331N/A print $! > "${PID_FILE}"
2976N/A
6331N/A # wait until server startup has finished: removes ${STARTING_FILE} when done
6331N/A if (( ${QUIET} )); then
6331N/A "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
6331N/A --targetFile "${STARTING_FILE}" \
6331N/A "${DJARGS[@]}"
6331N/A else
6331N/A "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
6331N/A --targetFile "${STARTING_FILE}" --logFile "${LOG_FILE}" \
6331N/A "${DJARGS[@]}"
6331N/A fi
6331N/A RC=$?
6331N/A # 1 => 'internal error', '2' => 'timeout'
6331N/A (( ${RC} != 0 )) && exit ${RC}
6331N/A
6331N/A # now check, whether the server is still running
6331N/A "${OPENDJ_JAVA_BIN}" -client ${SCRIPT_NAME_ARG} \
6331N/A -Dorg.opends.server.InstallRoot="${INSTALL_ROOT}" \
6331N/A -Dorg.opends.server.InstanceRoot="${INSTANCE_ROOT}" \
6331N/A org.opends.server.core.DirectoryServer \
6331N/A --configClass org.opends.server.extensions.ConfigFileHandler \
6331N/A --configFile "${CONFIG_FILE}" --checkStartability > /dev/null 2>&1
6331N/A # 98 => 'already started', otherwise server doesn't run
6331N/A (( $? == 98 )) && exit 0 || exit 1
486N/Afi
6331N/A
6331N/A# non-detach
6331N/Aif (( ${QUIET} )); then
6331N/A print $$ > "${PID_FILE}"
6331N/A rm -f "${LOG_FILE}"
6331N/A exec "${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.core.DirectoryServer \
6331N/A --configClass org.opends.server.extensions.ConfigFileHandler \
6331N/A --configFile "${CONFIG_FILE}" "${DJARGS[@]}" > /dev/null
6331N/Afi
6331N/A
6331N/Aprint $$ > "${PID_FILE}"
6331N/Arm -f "${LOG_FILE}"
6331N/Aexec "${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.core.DirectoryServer \
6331N/A --configClass org.opends.server.extensions.ConfigFileHandler \
6331N/A --configFile "${CONFIG_FILE}" "${DJARGS[@]}"