Tinkering with 2.3 startup scripts on RHEL / CentOS

From: Steve Jenkins <stevejenkins_at_gmail.com>
Date: Fri, 28 Jan 2011 12:35:43 -0800

I'm much more of a general hacker, with zero programming skills and
somewhat limited scripting skills. So what the $*&# am I doing on the
dev list? Funny you should ask... :)

I've been fiddling with the opendkim.init script in the 2.3.0-beta4
contrib directory, but in its default state I can't get it working on
a CentOS 5.5 box. Any command I try (service opendkim start, or stop,
or status) it just replies with nothing (and doesn't start or stop
opendkim).

Before I knew that script even existed in contrib, I had been managing
opendkim since the 2.2.0 version with a script that I hacked together
from a few different sources (which I'll paste below). That script
will start the opendkim process fine:

# service opendkim start
Starting OpenDKIM Milter: [ OK ]

But when I try these other commands I get output I don't want:

# service opendkim status
opendkim dead but subsys locked

even though it's still signing mail and a ps shows it's running:

# ps aux | grep opendkim
502 9445 0.0 0.0 5348 588 ? Ss 12:22 0:00
/usr/local/sbin/opendkim -x /etc/opendkim.conf
502 9446 0.0 0.0 25968 1648 ? Sl 12:22 0:00
/usr/local/sbin/opendkim -x /etc/opendkim.conf

Reload doesn't work either:

# service opendkim reload
Reloading OpenDKIM Milter config: [FAILED]

But the main issue is with a restart:

# service opendkim restart
Stopping OpenDKIM Milter: [FAILED]
Starting OpenDKIM Milter: [ OK ]

At which point the script starts and extra instance of opendkim,
filling my maillog with:

Jan 28 12:24:58 opendkim[19290]: OpenDKIM Filter: Unable to bind to
port inet:20209_at_localhost: Address already in use
Jan 28 12:24:58 opendkim[19290]: OpenDKIM Filter: Unable to create
listening socket on conn inet:20209_at_localhost
Jan 28 12:24:58 opendkim[19290]: smfi_opensocket() failed

then I have to manually kill all the processes and issue a fresh start command.

Can someone with more init scripting experience take a peek at the
following script and see what I'm doing wrong, or share the script
you're using on a RHEL or CentOS box?

Thanks,

SteveJ

================================================

#!/bin/bash
#
# opendkim Start and stop OpenDKIM.

# chkconfig: - 41 61
# description: OpenDKIM implements the DomainKeys Identified Mail
(DKIM) service and a milter-based filter application that can plug in
to any milter-aware MTA.
# processname: opendkim
# pidfile: /var/run/opendkim/opendkim.pid

### BEGIN INIT INFO
# Provides: opendkim
# Required-Start: opendkim
# Required-Stop: opendkim
# Short-Description: Start and stop OpenDKIM
# Description: DKIM milter
### END INIT INFO

# OpenDKIM startup script v1.2 for RHEL/CentOS/Fedora by Steve Jenkins
(SteveJenkins.com) - 12-01-2011
# Based on a script by Andrew Colin Kissa (TopDog) for dkim-milter - 28-05-2009
# Additional functionality to prevent multiple instances and a reload
handler by Chris LaJoie - 11-01-2011

. /etc/rc.d/init.d/functions

DAEMON=/usr/local/sbin/opendkim
PID_FILE=/var/run/opendkim/opendkim.pid
CONF_FILE=/etc/opendkim.conf
RETVAL=0

start() {
 echo -n $"Starting OpenDKIM Milter: "
 daemon --pidfile=$PID_FILE $DAEMON -x $CONF_FILE
 RETVAL=$?
 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/opendkim
 echo
 return $RETVAL
}

stop() {
 echo -n $"Stopping OpenDKIM Milter: "
 killproc -p $PID_FILE opendkim
 RETVAL=$?
 echo
 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/opendkim
 return $RETVAL
}

restart() {
 stop
 start
}

# PART 1/2 OF RELOAD HANDLER FOR OPENDKIM VERSION 2.3+
# UNCOMMENT THE FOLLOWING 7 LINES ONLY IF USING OPENDKIM 2.3+
reload() {
 echo -n $"Reloading OpenDKIM Milter config: "
 killproc -p $PID_FILE opendkim -SIGUSR1
 RETVAL=$?
 echo
 return $RETVAL
}

case "$1" in
 start)
  start
  ;;
 stop)
  stop
  ;;
# PART 2/2 OF RELOAD HANDLER FOR OPENDKIM VERSION 2.3+
# UNCOMMENT THE FOLLOWING 3 LINES ONLY IF USING OPENDKIM 2.3+
 reload)
  reload
  ;;
restart)
  restart
  ;;
 status)
  status -p $PID_FILE opendkim
  ;;
 condrestart)
  [ -f /var/lock/subsys/opendkim ] && restart || :
  ;;
 *)
  echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
  exit 1
esac

exit $?
Received on Fri Jan 28 2011 - 20:35:57 PST

This archive was generated by hypermail 2.3.0 : Mon Oct 29 2012 - 23:33:08 PST