6331N/A#!/bin/ksh93
6331N/A#
6331N/A# $Id$
2976N/A#
2976N/A# CDDL HEADER START
2976N/A#
2976N/A# The contents of this file are subject to the terms of the
2976N/A# Common Development and Distribution License, Version 1.0 only
2976N/A# (the "License"). You may not use this file except in compliance
2976N/A# with the License.
2976N/A#
2976N/A# You can obtain a copy of the license at
2976N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE
2976N/A# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
2976N/A# See the License for the specific language governing permissions
2976N/A# and limitations under the License.
2976N/A#
2976N/A# When distributing Covered Code, include this CDDL HEADER in each
2976N/A# file and include the License file at
2976N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
2976N/A# add the following below this CDDL HEADER, with the fields enclosed
2976N/A# by brackets "[]" replaced with your own identifying information:
2976N/A# Portions Copyright [yyyy] [name of copyright owner]
2976N/A#
2976N/A# CDDL HEADER END
2976N/A#
2976N/A#
5022N/A# Copyright 2008-2010 Sun Microsystems, Inc.
6331N/A# Portions Copyright 2010-2011 ForgeRock AS
6331N/A# Portions Copyright 2013 Jens Elkner
6331N/A
6331N/A# Fallback to use on non-SunOS
6331N/ADEFAULT_INSTANCE_DIR=/var/share/ldap
6331N/A# Fallback to use on SunOS
6331N/ADEFAULT_SMF_FMRI=network/ldap/opendj@VERS@:default
2976N/A
2976N/A#
4915N/A# Display an error message
4915N/A#
6331N/Afunction display_java_not_found_error {
6331N/A print -u2 '
6331N/APlease set OPENDJ_JAVA_HOME to the root of a Java 6 update 10 (or higher)
6331N/Ainstallation or edit the java.properties file and then run the dsjavaproperties
6331N/Ascript to specify the Java version to be used.'
4915N/A}
4915N/A
6331N/A# function that tests the JAVA_HOME env variable.
6331N/Afunction test_java_home {
6331N/A [[ -z ${JAVA_HOME} ]] && display_java_not_found_error && exit 999
6331N/A
6331N/A export OPENDJ_JAVA_BIN="${JAVA_HOME}/bin/java"
6331N/A [[ ! -x ${OPENDJ_JAVA_BIN} ]] && display_java_not_found_error && exit 999
4915N/A}
4915N/A
6331N/A# function that tests the JAVA_BIN env variable.
6331N/Afunction test_java_bin {
6331N/A if [[ -n ${JAVA_BIN} && -x ${JAVA_BIN} ]]; then
6331N/A export OPENDJ_JAVA_BIN="${JAVA_BIN}"
6331N/A return
6331N/A fi
6331N/A test_java_home
4915N/A}
4915N/A
6331N/A# function that tests the java executable in the PATH env variable.
6331N/Afunction test_java_path {
6331N/A export OPENDJ_JAVA_BIN="${ whence java ; }"
6331N/A [[ -n $OPENDJ_JAVA_BIN && -x ${OPENDJ_JAVA_BIN} ]] && return
6331N/A test_java_bin
6331N/A}
6331N/A
5636N/A# function that tests the OPENDJ_JAVA_HOME env variable.
6331N/Afunction test_opendj_java_home {
6331N/A if [[ -z ${OPENDJ_JAVA_HOME} ]]; then
6331N/A test_java_path
6331N/A return
6331N/A fi
6331N/A export OPENDJ_JAVA_BIN="${OPENDJ_JAVA_HOME}/bin/java"
6331N/A [[ -x ${OPENDJ_JAVA_BIN} ]] || test_java_path
5636N/A}
5636N/A
5636N/A# function that tests the OPENDJ_JAVA_BIN env variable.
6331N/Afunction test_opendj_java_bin {
6331N/A if [[ -z ${OPENDJ_JAVA_BIN} ]]; then
6331N/A test_opendj_java_home
6331N/A elif [[ -x ${OPENDJ_JAVA_BIN} ]]; then
6331N/A export OPENDJ_JAVA_BIN
6331N/A else
6331N/A test_java_path
6331N/A fi
4915N/A}
4915N/A
2976N/A# function that sets the java home
6331N/Afunction set_java_home_and_args {
6331N/A [[ -r ${INSTANCE_ROOT}/lib/set-java-home ]] && \
6331N/A . "${INSTANCE_ROOT}"/lib/set-java-home
6331N/A test_opendj_java_bin
5636N/A}
4915N/A
4243N/A# Determine whether the detected Java environment is acceptable for use.
6331N/Afunction test_java {
6331N/A # this call just tests the java version compatibility (for now: If the
6331N/A # JVM vendor is "Sun Microsystems Inc.", than JVM version string must be
6331N/A # lexicographically greater or equal to 1.6.0_10. Otherwise it is
6331N/A # assumed, that the JVM is compatible) and known args.
6331N/A typeset ERRMSG='' LC_ALL= LC_MESSAGES=C
6331N/A ERRMSG=${ "${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} \
6331N/A -Dorg.opends.server.InstallRoot="${INSTALL_ROOT}" \
6331N/A org.opends.server.tools.InstallDS --testOnly 2>&1 ; }
6331N/A integer RC=$?
6331N/A (( ${RC} == 0 )) && return 0
6331N/A
6331N/A if (( ${RC} == 8 )); then
6331N/A # This is a particular error code that means that the Java version
6331N/A # is not supported. Let InstallDS to display the localized error msg
6331N/A print -u2 "${ERRMSG}"
6331N/A exit 999
6331N/A fi
6331N/A if (( ${RC} == 2 )); then
6331N/A # the error message includes the "Usage info" - so strip off the bloat
6331N/A ERRMSG="${ERRMSG%%$'\n\n'This utility*}"
6331N/A print -u2 "Argument parse error(s):${ERRMSG##*arguments:}"
6331N/A print -u2 'To fix this problem, check your OPENDJ_JAVA_ARGS' \
6331N/A 'environment variable (if explicitly set), check your' \
6331N/A "'${INSTANCE_ROOT}/config/java.properties'" 'file and re-run' \
6331N/A "'${INSTALL_ROOT}/bin/dsjavaproperties'."
6331N/A exit 999
6331N/A fi
6331N/A if (( ${RC} != 8 || ${RC} != 1 )); then
6331N/A print -u2 "${ERRMSG}"
6331N/A exit 999
6331N/A fi
6331N/A
6331N/A # Since no other tests are done, this must be a JVM error.
6331N/A print -u2 'The following Java invocation error occured:\n' "${ERRMSG}"
6331N/A [[ -n ${OPENDJ_JAVA_ARGS} ]] && \
6331N/A print -u2 'OPENDJ_JAVA_ARGS=' "${OPENDJ_JAVA_ARGS}"
6331N/A print -u2 '
6331N/A
6331N/ATo fix the problem:
6331N/A 1. Delete the following file if it exists:
6331N/A ' "${INSTANCE_ROOT}/lib/set-java-home" '
6331N/A 2. Check the Java properties file for correct *.java-home and *.java-args
6331N/A settings. See:
6331N/A ' "${INSTANCE_ROOT}/config/java.properties" '
6331N/A 3. Run the following command-line tool to persist the changes made:
6331N/A ' "${INSTALL_ROOT}/bin/dsjavaproperties" '
6331N/A 4. When you run an OpenDJ tool, make sure, that OPENDJ_* environment
6331N/A variables are not already set.'
6331N/A exit 999
2976N/A}
2976N/A
2976N/A# Explicitly set the PATH, LD_LIBRARY_PATH, LD_PRELOAD, and other important
2976N/A# system environment variables for security and compatibility reasons.
6331N/Afunction set_environment_vars {
6331N/A # first unset everything we definitely do not need
6331N/A typeset KEEP=' COLUMNS DBUS_SESSION_BUS_ADDRESS DEFAULT_INSTANCE_DIR DEFAULT_SMF_FMRI DISPLAY FNLIST FNTRACE HOME HOST INSTALL_ROOT INSTANCE_ROOT JAVA_BIN JAVA_HOME KSH_VERSION LANG LC_COLLATE LC_CTYPE LC_MESSAGES LC_TIME LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64 LINENO LINES LOGNAME MISC_ARGS NLSPATH OLD_SCRIPT_NAME OPENDJ_INVOKE_CLASS OPENDJ_JAVA_ARGS OPENDJ_JAVA_BIN OPENDJ_JAVA_HOME OPTIND ORIGINAL_JAVA_ARGS ORIGINAL_JAVA_BIN ORIGINAL_JAVA_HOME PATH PPID PS1 PS2 PS3 PS4 PWD RANDOM REMOTEHOST SCRIPT_ARGS SCRIPT_NAME SCRIPT_NAME_ARG SCRIPT_UTIL_CMD SECONDS SESSION_MANAGER SHELL SHLVL SMF_FMRI SSH_AGENT_PID SSH_AUTH_SOCK TERM TMOUT TMPDIR TZ USER USERNAME XAUTHORITY XDG_DATA_DIRS XDG_SESSION_COOKIE _AST_FEATURES _ VAR KEEP PWD '
6331N/A set | while read LINE ; do
6331N/A LINE=${LINE%%=*}
6331N/A [[ -z ${.sh.match} || ${KEEP} =~ " ${LINE} " ]] && continue
6331N/A typeset -n VAR=${LINE}
6331N/A unset VAR
6331N/A done
6331N/A typeset -n VAR
6331N/A for VAR in LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64 ; do
6331N/A [[ ${VAR} != 'libumem.so' ]] && unset VAR
6331N/A done
6331N/A SCRIPT_NAME_ARG="-Dorg.opends.server.scriptName=${SCRIPT_NAME}"
6331N/A export PATH='/usr/bin:/usr/sbin'
6331N/A# LD_LIBRARY_PATH='' LD_LIBRARY_PATH_32='' LD_LIBRARY_PATH_64='' \
6331N/A# LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
2976N/A}
2976N/A
2976N/A# Configure the appropriate CLASSPATH.
6331N/Afunction set_classpath {
6331N/A typeset JAR
6331N/A CLASSPATH=''
6331N/A [[ -d ${INSTANCE_ROOT}/classes ]] && CLASSPATH+=":${INSTANCE_ROOT}"/classes
6331N/A for JAR in ~(N)"${INSTALL_ROOT}"/lib/*.jar ; do
6331N/A [[ -n ${JAR} ]] && CLASSPATH+=":${JAR}"
6331N/A done
6331N/A if [[ ${INSTALL_ROOT} != ${INSTANCE_ROOT} ]]; then
6331N/A for JAR in ~(N)"${INSTANCE_ROOT}"/lib/*.jar ; do
6331N/A [[ -n ${JAR} ]] && CLASSPATH+=":${JAR}"
6331N/A done
6331N/A fi
6331N/A export CLASSPATH=${CLASSPATH:1} # remove leading :
6331N/A}
6331N/A
6331N/Afunction isVersionOrHelp {
6331N/A typeset opt
6331N/A for opt in "$@" ; do
6331N/A case "$opt" in
6331N/A '-V'|'--version'|'-?'|'-H'|'--help'|'-F'|'--fullversion') return 0;;
6331N/A esac
6331N/A done
6331N/A return 1
2976N/A}
2976N/A
6331N/Afunction getprop {
6331N/A typeset PROPVAL=''
6331N/A if [[ ${ uname -s ; } == 'SunOS' && ${ id -un ; } == 'ldapd' ]]; then
6331N/A if svcprop -q -p "$1" ${SMF_FMRI} ; then
6331N/A PROPVAL=${ svcprop -p $1 ${SMF_FMRI}; }
6331N/A [[ $PROPVAL == '""' ]] && PROPVAL=""
6331N/A # remove space escaping backslashes
6331N/A PROPVAL="${PROPVAL//\\ / }"
6331N/A fi
6331N/A if [[ -z ${PROPVAL} || ${PROPVAL:0:1} != '/' ]]; then
6331N/A # Actually this should never happen, however, sometimes people are
6331N/A # really smart ;-)
6331N/A [[ -z ${INSTANCE_ROOT} ]] && X='set' || X='an absolute path'
6331N/A print -u2 '
6331N/AThe config/datadir property for the service' "${SMF_FMRI}" 'is not' $X'.
6331N/AIt should point to the OpenDJ data directory for this service instance.
6331N/APlease set it and try again. E.g.:
6331N/A svccfg -s '"${SMF_FMRI}"" 'setprop config/datadir = /var/share/opendj'"'
6331N/A svccfg -s '"${SMF_FMRI}"' refresh
6331N/A'
6331N/A exit 999
6331N/A fi
3885N/A fi
6331N/A if [[ -z ${PROPVAL} ]]; then
6331N/A [[ ${ id -un ; } == 'ldapd' ]] \
6331N/A && PROPVAL=${DEFAULT_INSTANCE_ROOT} \
6331N/A || PROPVAL=${HOME}/opendj
6331N/A fi
6331N/A print -- "${PROPVAL}"
3885N/A}
3885N/A
6331N/A# Try to give the user a hint. Actually this should be done by the
6331N/A# application/utility and return an appropriate error code, but it doesn't :(
6331N/Afunction checkInstanceDir {
6331N/A typeset EXT=''
6331N/A [[ ${SCRIPT_NAME} != 'dsjavaproperties' ]] && EXT='.startok'
6331N/A [[ -f "${INSTANCE_ROOT}"/config/hostname || \
6331N/A -f "${INSTANCE_ROOT}/config/config.ldif${EXT}" ]] && return
6331N/A# Or if one wants check for populated instances, only.
6331N/A# if [[ ( -f ${INSTANCE_ROOT}/config/config.ldif ) \
6331N/A# && -n ${ ls ${INSTANCE_ROOT}/config/archived-configs/*.gz 2>/dev/null; } \
6331N/A# && -n ${ ls ${INSTANCE_ROOT}/db/* 2>/dev/null ; } ]] \
6331N/A# then
6331N/A# return
6331N/A# fi
6331N/A if [[ ${ uname -s ; } == 'SunOS' ]]; then
6331N/A print -u2 '
6331N/AIt seems, that the following service has not yet been initialized:
6331N/A\t'"${SMF_FMRI}"'
6331N/APlease run' "${INSTALL_ROOT}/setup" '.\n'
6331N/A else
6331N/A print -u2 '
6331N/AThe instance data directory "'${INSTANCE_ROOT}'"
6331N/Aseems to contain no valid data. If you want to use a different instance data
6331N/Adirectory, set your INSTANCE_ROOT environment variable to the appropriate
6331N/Apath. Otherwise, to initialize the shown directory shown above, run
6331N/A'"${INSTALL_ROOT}/setup"' .\n'
6331N/A fi
6331N/A exit 999
6331N/A}
2976N/A
6331N/Afunction checkEnv {
6331N/A integer CHECK_INSTANCE=0
6331N/A [[ ${1} == '-i' ]] && CHECK_INSTANCE=1 && shift
6331N/A typeset SCRIPT_UTIL_CMD="$1"
6331N/A # Capture the location of this script so that we can use them to create
6331N/A # appropriate paths.
6331N/A INSTALL_ROOT="${.sh.file%/*/*}"
3860N/A
6331N/A if [[ ${ uname -s ; } == 'SunOS' && ${ id -un ; } == 'root' ]]; then
6331N/A print -u2 "\nWARNING: ${SCRIPT_NAME} should not be run as user 'root'!\n"
6331N/A fi
6331N/A # If no SMF_FMRI is set (interactive use), we choose the default instance.
6331N/A [[ -z ${SMF_FMRI} ]] && SMF_FMRI='network/ldap/opendj@VERS@:default'
6331N/A [[ -z ${INSTANCE_ROOT} ]] && INSTANCE_ROOT="${ getprop config/datadir ; }"
2976N/A
6331N/A case "${SCRIPT_UTIL_CMD}" in
6331N/A 'set-full-environment-and-test-java')
6331N/A set_java_home_and_args
6331N/A set_environment_vars
6331N/A set_classpath
6331N/A test_java
6331N/A ;;
6331N/A 'set-full-environment')
6331N/A set_java_home_and_args
6331N/A set_environment_vars
6331N/A set_classpath
6331N/A ;;
6331N/A 'set-java-home-and-args')
6331N/A set_java_home_and_args
6331N/A ;;
6331N/A 'set-environment-vars')
6331N/A set_environment_vars
6331N/A ;;
6331N/A 'set-classpath')
6331N/A set_classpath
6331N/A ;;
6331N/A 'test-java')
6331N/A test_java
6331N/A ;;
6331N/A esac
6331N/A (( ! CHECK_INSTANCE )) && return
6331N/A
6331N/A # No check for --version or --help option
6331N/A isVersionOrHelp "$@" && return 0
6331N/A checkInstanceDir
6331N/A}
6331N/A
6331N/A# list all defined script functions known at this point
6331N/A[[ -n ${FNLIST} ]] && typeset +f
6331N/A
6331N/A# If set to 'ALL', trace all functions, otherwise trace only the functions whose
6331N/A# name is in this comma or whitespace separated list
6331N/Aif [[ -n ${FNTRACE} ]]; then
6331N/A [[ ${FNTRACE} == 'ALL' ]] && typeset -ft ${ typeset +f ; } || \
6331N/A typeset -ft ${FNTRACE//,/ }
2976N/Afi