Last active
August 29, 2015 14:21
-
-
Save bmatthewshea/50e2038563b103e466ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# | |
# postgrey start/stop the postgrey greylisting deamon for postfix | |
# (priority should be smaller than that of postfix) | |
# | |
# Author: (c)2004-2006 Adrian von Bidder <[email protected]> | |
# Based on Debian sarge's 'skeleton' example | |
# Distribute and/or modify at will. | |
# | |
# Version: $Id: postgrey.init 1436 2006-12-07 07:15:03Z avbidder $ | |
# | |
### BEGIN INIT INFO | |
# Provides: postgrey | |
# Required-Start: $syslog $local_fs $remote_fs | |
# Required-Stop: $syslog $local_fs $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start/stop the postgrey daemon | |
### END INIT INFO | |
set -e | |
NAME=postgrey | |
PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
DAEMON=/usr/sbin/postgrey | |
# PROCNAME patch for bad stop start based off /proc/PID/stat | |
# (is now truncated 15 char path) (Ubuntu 12.xx+) - in this case = '/usr/sbin/postg' | |
PROCNAME=`echo $DAEMON | cut -c -15` | |
DESC="postfix greylisting daemon" | |
# ADDED PIDFOLDER | |
PIDFOLDER=/var/run/$NAME | |
PIDFILE=$PIDFOLDER/$NAME.pid | |
SCRIPTNAME=/etc/init.d/$NAME | |
# Gracefully exit if the package has been removed. | |
test -x $DAEMON || exit 0 | |
. /lib/lsb/init-functions | |
# Read config file if it is present. | |
if [ -r /etc/default/$NAME ] | |
then | |
. /etc/default/$NAME | |
fi | |
# added function to recreate dir | |
# Create new PID folder in /run if not exist | |
check_pid_dir() { | |
if [ ! -d $PIDFOLDER ]; then | |
mkdir $PIDFOLDER | |
chmod 0755 $PIDFOLDER | |
fi | |
} | |
POSTGREY_OPTS="--pidfile=$PIDFILE --daemonize $POSTGREY_OPTS" | |
if [ -z "$POSTGREY_TEXT" ]; then | |
POSTGREY_TEXT_OPT="" | |
else | |
POSTGREY_TEXT_OPT="--greylist-text=$POSTGREY_TEXT" | |
fi | |
ret=0 | |
case "$1" in | |
start) | |
#added function to recreate dir (from ssh script) | |
check_pid_dir | |
log_daemon_msg "Starting $DESC" "$NAME" | |
if start-stop-daemon --start --oknodo --quiet \ | |
--pidfile $PIDFILE --name $NAME \ | |
--startas $DAEMON -- $POSTGREY_OPTS "$POSTGREY_TEXT_OPT" | |
then | |
log_end_msg 0 | |
else | |
ret=$? | |
log_end_msg 1 | |
fi | |
;; | |
stop) | |
log_daemon_msg "Stopping $DESC" "$NAME" | |
if start-stop-daemon --stop --oknodo --quiet \ | |
--pidfile $PIDFILE --name $PROCNAME | |
then | |
log_end_msg 0 | |
else | |
ret=$? | |
log_end_msg 1 | |
fi | |
rm -f $PIDFILE | |
;; | |
reload|force-reload) | |
log_action_begin_msg "Reloading $DESC configuration..." | |
if start-stop-daemon --stop --signal 1 --quiet \ | |
--pidfile $PIDFILE --name $PROCNAME | |
then | |
log_action_end_msg 0 | |
else | |
ret=$? | |
log_action_end_msg 1 | |
fi | |
;; | |
restart) | |
$0 stop | |
$0 start | |
ret=$? | |
;; | |
status) | |
status_of_proc -p $PIDFILE $DAEMON "$NAME" 2>/dev/null | |
ret=$? | |
;; | |
*) | |
echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|status}" >&2 | |
exit 1 | |
;; | |
esac | |
exit $ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment