#!/bin/ksh93 MAN='[-?$Id: unconfigure 560 2013-05-22 07:36:34Z elkner $] [-copyright] { [+?Copyright 2013 Jens Elkner] } [-license?CDDL 1.0 (see http://opensource.org/licenses/cddl-1.0)] [+NAME?'"${.sh.file##*/}"' - unconfigures an OpenDJ instance] [+DESCRIPTION?A convinience script to disable the related OpenDJ service instance and remove its configuration file from the related instance data directory. Use option \b-r\b to remove the related instance data directory completely (and thus \ball\b data stored in the instance!). However, re-using a data instance directory from an unconfigured instance is not supported and may result in an unexpected behavior!] [H:help?Display this usage information and exit.] [V:version?Display directory server version information and exit.] [r:realclean?Forcibly remove the \bentire\b data directory of the related OpenDJ instance, no matter whether it is still in use.] [+EXAMPLES]{ [+Example 1?The following example unconfigures the default OpenDJ instance:] [+?$ SMF_FMRI=opendj25:test pfexec ./unconfigure -r] [+Example 2?Check the service config properties:] [+?$ svcprop -p config network/ldap/opendj25:test] [+Example 3?Remove the OpenDJ service instance "test" from the system:] [+?# svccfg -s network/ldap/opendj25 "delete test"] [+?# svccfg -s network/ldap/opendj25 refresh] } [+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), \bconfigure\b(1), \bsetup\b(1), \bopendj\b(5)] } ' [[ ${FNTRACE} == 'ALL' || ${FNTRACE} == 'main' ]] && set -x INSTALL_ROOT="${.sh.file%/*}" SCRIPT_NAME='unconfigure' function showVersion { checkEnv 'set-full-environment-and-test-java' "${OPENDJ_JAVA_BIN}" ${OPENDJ_JAVA_ARGS} ${SCRIPT_NAME_ARG} \ -DINSTALL_ROOT="${INSTALL_ROOT}" \ org.opends.server.tools.configurator.Configurator --version } function showUsage { getopts -a ${.sh.file##*/} "${ print $MAN ; }" X --man } function makeClean { typeset X=${ svcs -H -o state ${SMF_FMRI} 2>/dev/null ; } if [[ -z $X ]]; then print -u2 'The system does not know anything about the SMF service' \ "'${SMF_FMRI}'." exit 1 fi if [[ $X != 'disabled' ]]; then if ! /usr/sbin/svcadm disable -s "${SMF_FMRI}" 2>/dev/null ; then print -u2 " The service '${SMF_FMRI}' is still running.\n" \ 'Please disable it before trying to unconfigure again.' exit 1 fi fi print "Cleaning up instance data dir '${INSTANCE_ROOT}' ..." [[ ! -d ${INSTANCE_ROOT} ]] && print 'Done.' && return 0 if [[ -d ${INSTANCE_ROOT}/config/archived-configs ]]; then mv "${INSTANCE_ROOT}"/config/archived-configs \ "${INSTANCE_ROOT}"/config/archived-configs.old || exit 1 fi # the file start-ds checks for for X in hostname config.ldif.startok ; do [[ -f "${INSTANCE_ROOT}"/config/${X} ]] && mv "${INSTANCE_ROOT}"/config/${X} "${INSTANCE_ROOT}"/config/${X}.old done # If those exist, setup would try to re-use them and errors out, if # passwords do not match ... for X in keystore.pin truststore keystore ; do FILE="${INSTANCE_ROOT}/config/$X" [[ -f ${FILE} ]] && mv "${FILE}" "${FILE}.old" done (( ! ${REAL_CLEAN} )) && { print 'Done.' ; return 0 ; } # don't wanna rm -rf / ;-) if [[ ! -f ${INSTANCE_ROOT}/config/java.properties ]]; then print -u2 "'${INSTANCE_ROOT}' does not look like a OpenDJ instance" \ 'data dir. Please remove it manually.' exit 1 fi # try to get it clean as possible rm -rf "${INSTANCE_ROOT}"/* || exit 1 # it may belong to a different user ... rmdir "${INSTANCE_ROOT}" print 'Done.' } integer REAL_CLEAN=0 while getopts -a "${.sh.file##*/}" "${ print $MAN ; }" option ; do case "$option" in H|'?') showUsage ; exit 0 ;; V) showVersion ; exit $? ;; r) REAL_CLEAN=1 ;; esac done X=$(( OPTIND - 1 )) shift $X # Set env vars . "${INSTALL_ROOT}"/lib/_script-util.sh checkEnv makeClean