178N/A#!/bin/ksh93
178N/A#
178N/A# $Id: start-ds 560 2013-05-22 07:36:34Z elkner $
178N/A#
178N/A# CDDL HEADER START
178N/A#
178N/A# The contents of this file are subject to the terms of the
178N/A# Common Development and Distribution License, Version 1.0 only
178N/A# (the "License"). You may not use this file except in compliance
178N/A# with the License.
178N/A#
178N/A# You can obtain a copy of the license at
178N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE
178N/A# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
178N/A# See the License for the specific language governing permissions
178N/A# and limitations under the License.
178N/A#
178N/A# When distributing Covered Code, include this CDDL HEADER in each
178N/A# file and include the License file at
178N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
178N/A# add the following below this CDDL HEADER, with the fields enclosed
1400N/A# by brackets "[]" replaced with your own identifying information:
178N/A# Portions Copyright [yyyy] [name of copyright owner]
814N/A#
814N/A# CDDL HEADER END
814N/A#
814N/A# Copyright 2006-2009 Sun Microsystems, Inc.
814N/A# Portions Copyright 2011 ForgeRock AS
178N/A# Portions Copyright 2013 Jens Elkner
178N/A
178N/AINSTALL_ROOT="${.sh.file%/*/*}" SCRIPT_NAME='start-ds'
345N/A
618N/A# Set environment variables
178N/ACHECK_VERSION='yes'
178N/A. "${INSTALL_ROOT}"/lib/_script-util.sh
844N/A# would use -i, but -s is also just version info but is not a common switch
844N/AcheckEnv 'set-full-environment-and-test-java'
618N/A
1273N/Ainteger QUIET=0 DETACH=1 INFO=0
178N/Atypeset -a DJARGS=( )
178N/Aif isVersionOrHelp "$@" ; then
178N/A INFO=1
178N/Aelse
178N/A if [[ ${ LC_ALL= LC_MESSAGES=C tty ; } == 'not a tty' ]]; then
519N/A # remove no detach arg and assume, it is started by SMF
519N/A for ARG in "$@" ; do
178N/A [[ ${ARG} == '-N' || ${ARG} == '--nodetach' ]] && continue
178N/A [[ ${ARG} == '-Q' || ${ARG} == '--quiet' ]] && QUIET=1
178N/A [[ ${ARG} == '-F' || ${ARG} == '--fullVersion' ]] && INFO=1
178N/A [[ ${ARG} == '-s' || ${ARG} == '--systemInfo' ]] && INFO=1
178N/A DJARGS+=( "${ARG}" )
178N/A done
178N/A else
178N/A for ARG in "$@" ; do
178N/A [[ ${ARG} == '-N' || ${ARG} == '--nodetach' ]] && DETACH=0
441N/A [[ ${ARG} == '-Q' || ${ARG} == '--quiet' ]] && QUIET=1
178N/A [[ ${ARG} == '-F' || ${ARG} == '--fullVersion' ]] && INFO=1
178N/A [[ ${ARG} == '-s' || ${ARG} == '--systemInfo' ]] && INFO=1
1400N/A DJARGS+=( "${ARG}" )
1400N/A done
1400N/A # issue a warning, if the service is running and one tries to start it
1400N/A # manually as well - let the app do the rest
178N/A if (( ! INFO )) && [[ ${ uname -s ; } == 'SunOS' ]]; then
178N/A STATE=''
178N/A [[ -n ${SMF_FMRI} ]] && \
178N/A STATE=${ svcs -H -o state ${SMF_FMRI} 2>/dev/null; }
178N/A if [[ -n ${STATE} && ${STATE} != 'disabled' ]]; then
1400N/A print -u2 "WARNING: The service '${SMF_FMRI}' is not disabled!"
178N/A fi
1400N/A fi
178N/A fi
1400N/Afi
178N/A
178N/A# Specify the locations of important files that may be used when the server
178N/A# is starting.
441N/ACONFIG_FILE="${INSTANCE_ROOT}"/config/config.ldif
178N/APID_FILE="${INSTANCE_ROOT}"/logs/server.pid
178N/ALOG_FILE="${INSTANCE_ROOT}"/logs/server.out
178N/ASTARTING_FILE="${INSTANCE_ROOT}"/logs/server.starting
178N/A
178N/Aif (( ${INFO} )); then
178N/A "${OPENDJ_JAVA_BIN}" -client ${SCRIPT_NAME_ARG} \
178N/A -Dorg.opends.server.InstallRoot="${INSTALL_ROOT}" \
178N/A -Dorg.opends.server.InstanceRoot="${INSTANCE_ROOT}" \
1400N/A org.opends.server.core.DirectoryServer \
1400N/A --configClass org.opends.server.extensions.ConfigFileHandler \
1400N/A --configFile "${CONFIG_FILE}" "$@"
1400N/A exit $?
1400N/Afi
1400N/AcheckInstanceDir
1400N/A
178N/A# We do not check for startability, since for non-Windows it just returns
178N/A# based on the passed arguments:
181N/A# 99 => 'start as detached'
178N/A# 100 => 'start as non-detached'
1400N/A# 103 => 'start as detached quiet'
1400N/A# 104 => 'start as non-detached quiet'
1400N/A# what we already know by parsing the args above. If an arg or instance problem
1400N/A# exists, exit 999 from checkEnv or checkInstance would prevent getting here.
178N/A# So doing a --checkStartability would not by us anything ...
178N/A
178N/Aif (( ${DETACH} )); then
178N/A touch "${STARTING_FILE}"
178N/A nohup "${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
178N/A -Dorg.opends.server.InstallRoot="${INSTALL_ROOT}" \
178N/A -Dorg.opends.server.InstanceRoot="${INSTANCE_ROOT}" \
178N/A org.opends.server.core.DirectoryServer \
178N/A --configClass org.opends.server.extensions.ConfigFileHandler \
178N/A --configFile "${CONFIG_FILE}" "${DJARGS[@]}" > "${LOG_FILE}" 2>&1 &
178N/A print $! > "${PID_FILE}"
178N/A
178N/A # wait until server startup has finished: removes ${STARTING_FILE} when done
if (( ${QUIET} )); then
"${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
--targetFile "${STARTING_FILE}" \
"${DJARGS[@]}"
else
"${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
--targetFile "${STARTING_FILE}" --logFile "${LOG_FILE}" \
"${DJARGS[@]}"
fi
RC=$?
# 1 => 'internal error', '2' => 'timeout'
(( ${RC} != 0 )) && exit ${RC}
# now check, whether the server is still running
"${OPENDJ_JAVA_BIN}" -client ${SCRIPT_NAME_ARG} \
-Dorg.opends.server.InstallRoot="${INSTALL_ROOT}" \
-Dorg.opends.server.InstanceRoot="${INSTANCE_ROOT}" \
org.opends.server.core.DirectoryServer \
--configClass org.opends.server.extensions.ConfigFileHandler \
--configFile "${CONFIG_FILE}" --checkStartability > /dev/null 2>&1
# 98 => 'already started', otherwise server doesn't run
(( $? == 98 )) && exit 0 || exit 1
fi
# non-detach
if (( ${QUIET} )); then
print $$ > "${PID_FILE}"
rm -f "${LOG_FILE}"
exec "${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
-Dorg.opends.server.InstallRoot="${INSTALL_ROOT}" \
-Dorg.opends.server.InstanceRoot="${INSTANCE_ROOT}" \
org.opends.server.core.DirectoryServer \
--configClass org.opends.server.extensions.ConfigFileHandler \
--configFile "${CONFIG_FILE}" "${DJARGS[@]}" > /dev/null
fi
print $$ > "${PID_FILE}"
rm -f "${LOG_FILE}"
exec "${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \
-Dorg.opends.server.InstallRoot="${INSTALL_ROOT}" \
-Dorg.opends.server.InstanceRoot="${INSTANCE_ROOT}" \
org.opends.server.core.DirectoryServer \
--configClass org.opends.server.extensions.ConfigFileHandler \
--configFile "${CONFIG_FILE}" "${DJARGS[@]}"