#!/bin/ksh93 # # "$Id: initd.script,v 1.3 2005/02/10 07:25:43 elkner Exp $" # # description: # Startup/shutdown script for the Cyrus SASL authentification daemon # # default: S/K39 0/K39 1/K39 2/S80 . /lib/svc/share/smf_include.sh SPATH='@CLIENT_BASEDIR@/sbin' DAEMON='saslauthd' # directory, where the socket should be created SOCKETDIR='/var/run' # the default authitification mechanism to use AUTH='shadow' # other options OPTIONS="" NAME='Cyrus SASL authentification daemon' # Read command line arguments method="$1" # %m instance="$2" # %i # Set defaults; SMF_FMRI should have been set, but just in case. if [[ -z ${SMF_FMRI} ]]; then [[ -z ${instance} ]] && instance='default' SMF_FMRI="svc:/network/saslauthd:${instance}" fi # Get a single value property. # $1 .. Name of the property to lookup # $2 .. vName, where to store the unescaped value # $3 .. Optional: SMF_FMRI to use (default: ${SMF_FMRI}) # return: 0 .. non-empty value found; 1 .. prop does not exist or is empty # 2 .. missing FMRI 3 .. usage error function getSvcProp { [[ -z $1 || -z $2 ]] && print -u2 "getSvcProp() requires 2 args" && return 3 typeset -n VAL=$2 typeset FMRI=$3 if [[ -z ${FMRI} ]]; then [[ -n ${SMF_FMRI} ]] && FMRI=${SMF_FMRI} || { VAL='' ; return 2 ; } fi VAL="${ svcprop -p $1 ${FMRI} 2>/dev/null ; }" [[ ${VAL} == '""' ]] && { VAL='' ; return 1 ; } # unescape VAL="${VAL//\\(['"''`';&()|^<>'\n''\t''\'\047])/\1}" # \047 .. squote return 0 } ZN=${ /sbin/zonename ; } [[ ${ZN} == 'global' ]] && ZPPID=1 || ZPPID=${ pgrep -x zsched 2>/dev/null ; } unset X VAL OPTS case "$method" in start) if [[ ! -x ${SPATH}/${DAEMON} ]]; then print -u2 "'${SPATH}/${DAEMON}' does not exist" exit ${SMF_EXIT_ERR_FATAL} fi PID=${ pgrep -x -u 0 -P ${ZPPID} ${DAEMON} ; } if [[ -z ${PID} ]]; then print -n "Starting $NAME ..." typeset -a OPTS typeset X getSvcProp config/authmech VAL || VAL="${AUTH}" OPTS+=( '-a' "${VAL}" ) getSvcProp config/sockdir VAL || VAL="${SOCKETDIR}" OPTS+=( '-m' "${VAL}" ) getSvcProp config/options VAL && opts+=( ${VAL} ) ${SPATH}/${DAEMON} "${OPTS[@]}" if (( $? )); then print 'failed.' exit ${SMF_EXIT_ERR_CONFIG} fi print 'done.' else print "${NAME} is already running." fi ;; stop) PID=${ pgrep -x -u 0 -P ${ZPPID} ${DAEMON} ; } if [[ -n ${PID} ]]; then print -n "Stopping ${NAME} ..." pkill -x -u 0 -P ${ZPPID} ${DAEMON} (( $? == 0 )) && print 'done.' fi ;; status) PID=${ pgrep -x -u 0 -P ${ZPPID} ${DAEMON} ; } [[ -n ${PID} ]] && print "$NAME is running." || \ print "$NAME is not running." ;; *) print "Usage: $0 {start|status|stop}" exit ${SMF_EXIT_ERR_FATAL} ;; esac exit ${SMF_EXIT_OK}