#! /bin/sh # ### BEGIN INIT INFO # Provides: batv-milter # Required-Start: $remote_fs $named $network $time # Required-Stop: $remote_fs $named $network $time # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start the BATV Milter daemon ### END INIT INFO PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/batv-milter NAME=batv-milter DESC="BATV Milter" RUNDIR=/var/run/$NAME USER=batv-milter GROUP=batv-milter CONFIG=/etc/batv-milter.conf DAEMON_OPTS= INSTANCES= test -x $DAEMON || exit 0 # Include batv-milter defaults if available if [ -f /etc/default/batv-milter ] then . /etc/default/batv-milter fi DAEMON_OPTS="--daemon yes --user $USER --group $GROUP $DAEMON_OPTS" start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started # Create the run directory if it doesn't exist if [ ! -d $RUNDIR ] then install -o $USER -g $GROUP -m 2755 -d $RUNDIR || return 2 fi PIDFILE=$RUNDIR/$1.pid start-stop-daemon --start --quiet --pidfile $PIDFILE --user $USER --name $NAME --startas $DAEMON --test > /dev/null || return 1 start-stop-daemon --start --quiet --pidfile $PIDFILE --user $USER --name $NAME --startas $DAEMON -- --config $CONFIG --pid-file $PIDFILE $DAEMON_OPTS || return 2 } stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred PIDFILE=$RUNDIR/$1.pid start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME --user $USER RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 # In case PID file isn't properly deleted: rm -f $PIDFILE return "$RETVAL" } start_multi () { for instance do CONFIG=/etc/batv-milter-$instance.conf start $instance || return $? echo -n "$instance " done } command=$1 shift case "$command" in start) echo -n "Starting $DESC: " if [ $# -eq 0 ] && [ "$INSTANCES" = "" ] then # Normal operation - start the single default instance # (The config file is specified by the $CONFIG variable, which # defaults to /etc/batv-milter.conf and can be overridden in # /etc/default/batv-milter.) start batv-milter || exit $? echo -n "batv-milter" elif [ $# -eq 0 ] then # Start the instances specified in the $INSTANCES variable start_multi $INSTANCES || exit $? else # Start the instances specified on the command line start_multi "$@" || exit $? fi echo "." ;; stop) echo -n "Stopping $DESC: " if [ $# -eq 0 ] then # Stop all running instances for pidfile in $RUNDIR/*.pid do if [ -e $pidfile ] then instance=`basename $pidfile .pid` stop $instance echo -n "$instance " fi done else # Stop the instances specified on the command line for instance do stop $instance echo -n "$instance " done fi echo "." ;; restart|force-reload) $0 stop "$@" $0 start "$@" || exit $? ;; *) echo "Usage: $0 {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0