#!/bin/ksh93 MAN='[-?$Id: configure 554 2013-04-22 09:12:58Z elkner $] [-copyright] { [+?Copyright 2013 Jens Elkner] } [-license?CDDL 1.0 (see http://opensource.org/licenses/cddl-1.0)] [+NAME?'"${.sh.file##*/}"' - prepares the data directory of an OpenDJ instance] [+DESCRIPTION?This command should be used to prepare the data directory, where an OpenDJ server instance stores its configuration, database and other files. It also configures the related SMF service. After running this script, OpenDJ \bsetup\b(1) must be executed to configure/initialize the server instance.] [+?If the server instance should run under the \bldapd\b account (the default) this script can be run by any user, which has the "OpenDJ Admin" profile assigned to it. The only requirement here is, that the instance data directory or, if it does not yet exist, its parent is owned by \bldapd\b:\bldapd\b. Otherwise this script needs to be run as user \broot\b.] [H:help?Displays this usage information and exit.] [V:version?Displays directory server version information and exit.] [p:instancePath]:[dir?The OpenDJ instance data directory to prepare (default: the value of the \bconfig/datadir\b property of the service \b$SMF_FMRI\b).] [u:userName]:[user:=ldapd?The user name of the instance owner to use.] [g:groupName]:[group:=ldapd?The group name of the instance owner to use.] [f:force?Do not care, whether the instance data dir is/seems to be already in use. Forcibly overwrite anything.] [O:obsolete?If set, the OpenDJ internal (cross platform) procedures will be used to prepare the data instance directory. Thus the \b-f\b option gets ignored in this mode and adjustments to the SMF properties of the related instance are not made.] [+EXAMPLES]{ [+Example 1?The following example assigns the "OpenDJ Admin" profile to the user "jackson":] [+?# usermod -P "OpenDJ Admin" jackson] [+Example 2?Check which profiles are assigned to user "jackson":] [+?$ profiles jackson] [+? OpenDJ Admin] [+? Basic Solaris User] [+? All] [+Example 3?The following example prepares the data directory for the default OpenDJ instance:] [+?$ ./configure --instancePath=/data/ldap/opendj] [+Example 4?Create a new OpenDJ service and initialize the instance (since not specified, it will use the default instance data directory /var/share/ldap/opendj:test):] [+?# svccfg -s network/ldap/opendj25 "add test"] [+?# svccfg -s network/ldap/opendj25:test "setprop general/complete = true"] [+?# svccfg -s network/ldap/opendj25 refresh] [+?$ SMF_FMRI=network/ldap/opendj25:test ./configure] [+?$ SMF_FMRI=network/ldap/opendj25:test ./setup] } [+ENVIRONMENTAL VARIABLES]{ [+SMF_FMRI?The service instance to use. If unset or empty, \bnetwork/ldap/opendj25:default\b will be used.] [+FNTRACE?A comma or whitespace separated list of script function names to trace during their execution.] } [+SEE ALSO]{ [+?\bsvccfg\b(1M), \bsvcprop\b(1), \bsvcadm\b(1M), \bsetup\b(1), \bunconfigure\b(1), \bopendj\b(5)] } ' [[ ${FNTRACE} == 'ALL' || ${FNTRACE} == 'main' ]] && set -x INSTALL_ROOT="${.sh.file%/*}" SCRIPT_NAME='configure' function configOldStyle { checkEnv 'set-full-environment-and-test-java' # To be able to overide a config: ${INSTANCE_ROOT}/config/archived-configs # must be empty and server is not running (i.e. # ${INSTANCE_ROOT}/locks/server.lock does not exist or is excl lockable). "${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \ -DINSTALL_ROOT="${INSTALL_ROOT}" \ org.opends.server.tools.configurator.Configurator "$@" RC=$? (( ${RC} == 50 || ${RC} == 51 )) && return 0 # help shown (( ${RC} == 10 )) && return 1 # syntax error return ${RC} # if != 0 -> other error } function getprop { typeset PROPVAL svcprop -q -p $1 ${SMF_FMRI} if (( $? == 0 )); then PROPVAL=${ svcprop -p $1 ${SMF_FMRI}; } [[ ${PROPVAL} == '""' ]] && PROPVAL="" PROPVAL=${PROPVAL//\\ / } print -- "${PROPVAL}" fi } function prepare { typeset X if [[ -z ${INSTANCE_ROOT} ]]; then X=${SMF_FMRI##*:} [[ ${X} == 'default' ]] && X='opendj' || X="opendj:${X}" INSTANCE_ROOT=/var/share/ldap/${X} fi if [[ -f ${INSTANCE_ROOT}/config/config.ldif ]] && (( ${NO_FORCE} )); then print -u2 "It seems, that the data dir '${INSTANCE_ROOT}' is already" \ 'prepared for OpenDJ. Use the option -f to forcibly overwrite it.' return 1 fi # just make sure, the service exists and is disabled X=${ svcs -H -o state ${SMF_FMRI} 2>/dev/null ; } if [[ -z $X ]]; then print -u2 'The system does not know anything about the service:\n' \ "'${SMF_FMRI}'!" return 1 fi if [[ $X != 'disabled' ]]; then print -u2 "Trying to disable service '${SMF_FMRI}' ..." if ! /usr/sbin/svcadm disable -s "${SMF_FMRI}"; then print -u2 'Failed. Disable service ${SMF_FMRI} first and try again.' return 1 fi print -u2 'Done.' fi # try to improve the chance, that copying templates succeed if [[ ! -d ${INSTANCE_ROOT} ]] && auths check solaris.file.chown ; then pfexec mkdir -p "${INSTANCE_ROOT}" 2>/dev/null && \ pfexec chown ${SUID}:${SGID} "${INSTANCE_ROOT}" 2>/dev/null fi print -u2 "\nPreparing instance data dir '${INSTANCE_ROOT}' ..." # copy tmpl_instance/* to $INSTANCE_ROOT if ! ${INSTALL_ROOT}/lib/_cptmpl_script.sh "$INSTANCE_ROOT" ; then print -u2 'Failed.\n' return 1 fi typeset -a LS=( ${ ls -ld "${INSTANCE_ROOT}/db" 2>/dev/null ; } ) if [[ ${LS[2]} != ${SUSER} || ${LS[3]} != ${SGROUP} ]]; then X='' if auths check solaris.file.chown ; then pfexec chown -R ${SUID}:${SGID} "${INSTANCE_ROOT}"/ && X='ok' fi if [[ -z $X ]]; then print -u2 "Failed (${INSTANCE_ROOT} needs to be owned by" \ "${SUSER}:${SGROUP}).\n" return 1 fi fi # check, whether we can survive w/o changeing anything typeset TODO='' X=${ getprop config/datadir ; } [[ $X != ${INSTANCE_ROOT} ]] && \ TODO="setprop config/datadir = \"${INSTANCE_ROOT}\"\n" X=${ getprop stop/group ; } [[ $X != ${SGROUP} ]] && \ TODO+="setprop stop/group = \"${SGROUP}\"\n" X=${ getprop start/group ; } [[ $X != ${SGROUP} ]] && \ TODO+="setprop start/group = \"${SGROUP}\"\n" X=${ getprop stop/user ; } [[ $X != ${SUSER} ]] && \ TODO+="setprop stop/user = \"${SUSER}\"\n" X=${ getprop start/user ; } [[ $X != ${SUSER} ]] && \ TODO+="setprop start/user = \"${SUSER}\"\n" [[ -z $TODO ]] && return 0 TODO+='refresh' # finally update the service parameters (the lazy/easy way) /usr/sbin/svccfg -s "${SMF_FMRI}" -f - 2>/dev/null \ <<< ${ print ${TODO} ; } (( ! $? )) && return 0 # probably startd or stopd prop needs to be changed -> perm denied print -u2 'Unable to change SMF properties!\n' \ 'Execute the following command (possibly as root) to fix them\n' \ "(otherwise ${SMF_FMRI} will not work properly):\n" X="/var/tmp/svcprops-${SMF_FMRI##*/}" integer I for (( I=0; I < 1024; I++ )); do [[ ! -e ${X}.${I} ]] && break done if (( $I == 1024 )); then print -u2 "/usr/sbin/svccfg -s ${SMF_FMRI} -f - <"${X}.${I}" # two prints on purpose! print -u2 "\t/usr/sbin/svccfg -s ${SMF_FMRI} \\" print -u2 "\t\t-f '${X}.${I}'" fi print '\n After that you should initialize the instance with:\n\n\t' \ "${INSTALL_ROOT}/setup --cli\n" return 2 } function showUsage { getopts -a ${.sh.file##*/} "${ print $MAN ; }" X --man } SUSER='ldapd' SGROUP='ldapd' integer NO_FORCE=1 OBSOLETE=0 while getopts -a "${.sh.file##*/}" "${ print $MAN ; }" option ; do case "$option" in H|'?') showUsage ; exit 0 ;; V) configOldStyle -V ; exit 0 ;; p) INSTANCE_ROOT="${OPTARG}" ;; u) SUSER=${OPTARG} ;; g) SGROUP=${OPTARG} ;; f) NO_FORCE=0 ;; O) OBSOLETE=1 ;; esac done X=$(( OPTIND - 1 )) shift $X typeset SUID=${ id -u ${SUSER:=_unknown_} 2>/dev/null ; } typeset SGID=${ id -g ${SGROUP:=_unknown_} 2>/dev/null ; } [[ -z ${SUID} ]] && print -u2 "Invalid user name '${SUSER}'." && exit 1 [[ -z ${SGID} ]] && print -u2 "Invalid group name '${SUSER}'." && exit 1 # Set env vars . "${INSTALL_ROOT}"/lib/_script-util.sh checkEnv # Launch configure if (( ! ${OBSOLETE} )); then prepare && \ print 'Done. Now you should initialize the instance with:\n\n\t' \ "${INSTALL_ROOT}/setup --cli\n" else configOldStyle --instancePath "$INSTANCE_ROOT" \ --userName ${SUSER} --groupName ${SGROUP} fi