#!/bin/ksh93 # Start/Stop Dovecot IMAP/POP server . /lib/svc/share/smf_include.sh CONFIG=/etc/dovecot/dovecot.conf BASEDIR=@CLIENT_BASEDIR@ DOVECOT="${BASEDIR}/sbin/dovecot" DOVECONF="${BASEDIR}/sbin/doveconf" # Since stupid IPS does not support post install scripts :( function postInstall { # do nothing if the default config already exists or templates don't [[ -e /etc/dovecot/dovecot.conf || ! -d /etc/dovecot/original ]] && return cp -p /etc/dovecot/original/dovecot.conf /etc/dovecot/ [[ -d /etc/dovecot/conf.d ]] && return cp -pr /etc/dovecot/original/conf.d /etc/dovecot/ # Add ports if missing to /etc/services if [[ ! -e /etc/services ]]; then cp /dev/null /etc/services chmod 644 /etc/services fi typeset -A S typeset SVC PP TAIL while read SVC PP TAIL ; do [[ -z ${SVC} || ${SVC:0:1} == '#' ]] && continue S["${SVC}"]="${PP}" done < /etc/services typeset -A SVCS SVCS[pop2]=( pp='109/tcp pop pop-2' desc='# Post Office Protocol - Vers. 2' ) SVCS[pop3]=( pp='110/tcp' desc='# Post Office Protocol - Vers. 3' ) SVCS[imap]=( pp='143/tcp' desc='# Internet Mail Access Protocol v2' ) SVCS[imaps]=( pp='993/tcp' desc='# Internet Mail Access Protocol v2 over SSL/TLS' ) SVCS[pop3s]=( pp='995/tcp' desc='# Post Office Protocol v2 over SSL/TLS' ) TAIL='' for SVC in ${!SVCS[@]} ; do PP="${S[${SVC}]}" [[ -z ${PP} || ${PP: -4} != '/tcp' ]] && \ TAIL+="${SVC}\t\t${SVCS[${SVC}].pp}\t\t${SVCS[${SVC}].desc}\n" done [[ -n ${TAIL} ]] && print -n "${TAIL}" >>/etc/services # Install default SSL stuff PP='/etc/ssl/certs/dovecot.pem' [[ -f ${PP}.default && ! -e ${PP} ]] && cp -p "${PP}.default" "${PP}" PP='/etc/ssl/keys/dovecot.pem' [[ -f ${PP}.default && ! -e ${PP} ]] && cp -p "${PP}.default" "${PP}" } function checkConfig { [[ -z ${SMF_FMRI} ]] && SMF_FMRI='dovecot:default' typeset VAL="${ svcprop -p config/file ${SMF_FMRI} 2>/dev/null ; }" [[ ${VAL} == '""' || -z ${VAL} ]] && VAL="${CONFIG}" [[ ${VAL} == "${CONFIG}" ]] && postInstall CONFIG="${VAL}" } function getRunDir { checkConfig if [[ -x ${DOVECONF} ]]; then RUNDIR=${ "${DOVECONF}" -c "${CONFIG}" base_dir 2>/dev/null ; } RUNDIR="${RUNDIR#*= }" fi if [[ -z ${RUNDIR} ]]; then print -u2 "No base_dir property set in '${CONFIG}' - exiting." exit ${SMF_EXIT_ERR_CONFIG} fi } RUNDIR='' ZN=${ /sbin/zonename ; } [[ ${ZN} == 'global' ]] && ZPPID=1 || ZPPID=${ pgrep -x zsched 2>/dev/null ; } case "$1" in start) if [[ ! -x ${DOVECOT} ]]; then print -u2 "'${DOVECOT}' is not executable" exit ${SMF_EXIT_ERR_FATAL} fi getRunDir if [[ ! -f ${CONFIG} ]]; then print -u2 "Missing config file '${CONFIG}'" exit ${SMF_EXIT_ERR_CONFIG} fi if [[ ! -d ${RUNDIR} ]]; then mkdir -p "${RUNDIR}" if (( $? )); then print -u2 "Unable to create directory '${RUNDIR}'" exit ${SMF_EXIT_ERR_CONFIG} fi fi chmod 0755 "${RUNDIR}" PID=${ pgrep -u 0 -P ${ZPPID} "${DOVECOT}" 2>/dev/null ; } if [[ -n ${PID} ]]; then print -u2 "'${DOVECOT}' is already running" exit ${SMF_EXIT_OK} fi ulimit -S -n ${ ulimit -H -n ; } "${DOVECOT}" -c "${CONFIG}" || exit ${SMF_EXIT_ERR_FATAL} ;; refresh) pkill -HUP -u 0 -P ${ZPPID} "${DOVECOT}" ;; stop) getRunDir if [[ -f ${RUNDIR}/master.pid ]]; then kill -INT $(< "${RUNDIR}/master.pid") fi PID=${ pgrep -u 0 -P ${ZPPID} "${DOVECOT}" 2>/dev/null ; } [[ -n ${PID} ]] && pkill -INT -u 0 -P ${ZPPID} "${DOVECOT}" ;; dump) # dump config [[ -x ${DOVECOT} ]] && "${DOVECOT}" -a ;; dumpnd) # dump non-default config values [[ -x ${DOVECOT} ]] && "${DOVECOT}" -n ;; buildopts) # dump build options [[ -x ${DOVECOT} ]] && \ "${DOVECOT}" --build-options ;; *) print "Usage: $0 { start | stop | refresh | dump | dumpnd | buildopts }" exit 1 ;; esac exit ${SMF_EXIT_OK}