#!/bin/sh DAEMON=emailrelay DAEMON_LONG_NAME="E-MailRelay" . /etc/init.d/modlibrc SPOOLDIR="$(echo "$EMAILRELAY_OPTIONS" | sed -n 's/^[ \t]*spool-dir //p')" config() { mkdir $SPOOLDIR 2>/dev/null } pre_start() { if [ ! -d "$SPOOLDIR" ]; then echo "$DAEMON_LONG_NAME can not find spool directory, failed." return 1 fi } start() { local STATIC_ARGS="--user=$DAEMON --pid-file=$PID_FILE" local CUSTOM_ARGS="$( echo "$EMAILRELAY_OPTIONS" | while read line; do echo "$line" | grep -q "^[ \t]*$" && continue echo "$line" | grep -q "^[ \t]*#" && continue echo "$line" | grep -qE "^close-stderr|^user |^pid-file " && continue echo "$line" | sed 's/^/--/;s/ /=/' done | sort -u )" modlib_startdaemon $DAEMON_BIN $STATIC_ARGS $CUSTOM_ARGS 2>/dev/null } startdaemon_post() { # wait for proper daemon startup, typically 0-2 seconds local cnt=0 while [ $cnt -le 9 ]; do [ -s $PID_FILE ] && kill -0 "$(cat $PID_FILE)" 2>/dev/null && break let cnt++ sleep 1 done } case $1 in ""|load) modlib_add_user_and_group $DAEMON [ ! -d "/tmp/flash/$DAEMON" ] && mkdir -p /tmp/flash/$DAEMON modreg file $DAEMON "filter" 'emailrelay-filter' 1 "emailrelay_filter" modreg file $DAEMON "auth" 'emailrelay.auth' 1 "emailrelay_auth" modreg file $DAEMON "pem" 'emailrelay.pem' 1 "emailrelay_pem" modreg file $DAEMON "verifier" 'emailrelay-verifier' 1 "emailrelay_verifier" modreg cgi $DAEMON "$DAEMON_LONG_NAME" modreg daemon $DAEMON modlib_start $EMAILRELAY_ENABLED ;; unload) modunreg file $DAEMON modunreg daemon $DAEMON modunreg cgi $DAEMON modlib_stop ;; start) modlib_start ;; stop) modlib_stop ;; restart) modlib_restart ;; status) modlib_status ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0