Skip to content

Instantly share code, notes, and snippets.

@briceburg
Created August 15, 2014 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briceburg/e76d93e77afc4988ecc2 to your computer and use it in GitHub Desktop.
Save briceburg/e76d93e77afc4988ecc2 to your computer and use it in GitHub Desktop.
CentOS / RedHat LSB init script for nullmailer MTA
#!/bin/bash
#
# nullmailer MTA
#
# chkconfig: - 85 15
# description: nullmailer centos init @iceburg_net
### BEGIN INIT INFO
# Provides: smtpdaemon
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description:
# Description:
### END INIT INFO
# Source function library.
. /etc/init.d/functions
RETVAL=0
prog=nullmailer
exec=/usr/sbin/nullmailer-send
lockfile=/var/lock/subsys/$prog
run_as=nullmail
logfile=/var/log/nullmailer/nullmailer.log
# Source config
if [ -f /etc/sysconfig/$prog ] ; then
. /etc/sysconfig/$prog
fi
start() {
[ -x $exec ] || exit 5
echo -n "Starting $prog: "
PIDS=`pidof -c $exec`
if [ -z "$PIDS" ]; then
# modified to use a double-fork technique in absence of start-stop-daemon...
runuser -s /bin/bash $run_as -c "((exec $exec >> $logfile 2>&1)&)"
RETVAL=$?
else
echo -n "$prog is already running"
RETVAL=1
fi
[ $RETVAL -eq 0 ] && touch $lockfile && success || failure
echo
return $RETVAL
}
stop() {
echo -n "Stopping $prog: "
PIDS=`pidof -c $exec`
if [ -n "$PIDS" ]; then
killall $exec
return $?
else
echo -n "$prog is not running"
RETVAL=1
fi
[ $RETVAL -eq 0 ] && rm -f $lockfile && success || failure
echo
return $RETVAL
}
status() {
echo -n "status not supported "
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo "Usage: $NAME {start|stop|status|restart}"
exit 1
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment