#! /bin/sh # This file is part of mailfrom filter. # Copyright (C) 2005, Sergey Poznyakoff # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA PIDFILE= DAEMON= ARGS="" PS="ps axwwww" mailfromd_start() { echo "Starting mailfromd..." rm -f $PIDFILE if eval $DAEMON $ARGS ; then if [ ! -r $PIDFILE ]; then sleep 1 test -r $PIDFILE || echo "mailfromd NOT started" >&2 fi else echo "mailfromd failed to start" >&2 fi } mailfromd_stop() { echo "Stopping mailfromd..." if [ -r $PIDFILE ]; then PID=`head -n 1 $PIDFILE` kill -TERM -$PID 2>/dev/null N=0 while [ -r $PIDFILE ] do N=$((N+1)) if [ $N -gt 5 ]; then break fi sleep 1 done if [ -r $PIDFILE ]; then echo "Still running. Killing it..." >&2 kill -KILL $PID 2>/dev/null rm $PIDFILE fi else echo "mailfromd is not running" >&2 fi } mailfromd_status() { if [ -r $PIDFILE ]; then echo "mailformd appears to be running at `head -n 1 $PIDFILE`" fi $PS | grep "[0-9]:[0-9][0-9] $DAEMON " | while read pid tt stat time command do echo $pid $command done } case $1 in start) mailfromd_start;; stop) mailfromd_stop;; restart) mailfromd_stop sleep 1 mailfromd_start;; status) mailfromd_status;; *) echo "Usage: $0 {start|stop|restart|status}" >&2;; esac # End of rc.mailfromd