1#!/bin/bash
2#
3# opendkim    Start and stop OpenDKIM.
4
5# chkconfig: - 41 59
6# description: OpenDKIM implements the DomainKeys Identified Mail (DKIM)
7#              service and a milter-based filter application that can plug
8#              in to any milter-aware MTA.
9# processname: opendkim
10# pidfile: /var/run/opendkim/opendkim.pid
11
12### BEGIN INIT INFO
13# Provides: opendkim
14# Short-Description: Start and stop OpenDKIM
15# Description:	OpenDKIM implements the DomainKeys Identified Mail
16#		(DKIM) service and a milter-based filter application
17#		that can plug in to any milter-aware MTA.
18### END INIT INFO
19
20# OpenDKIM startup script v2.0 for RHEL/CentOS/Fedora
21# by Steve Jenkins (SteveJenkins.com) - 03-24-2015
22# Based on a script by Andrew Colin Kissa (TopDog) for dkim-milter - 05-28-2009
23# - Additional functionality to prevent multiple instances and a reload
24#   handler by Chris LaJoie - 01-11-2011
25# - Added notification (along with with current PID) if "start" is issued when
26#   OpenDKIM is already running - 02-15-2011
27# - Added support to generate default keys on start - 08-22-2011
28# - Added support for /etc/sysconfig/opendkim override of default init script
29#   setup parameters - 09-19-2011
30# - Changed default stop priority - 09-19-2011
31# - Updated success and warning outputs for default key generation - 09-20-2011
32# - Changed default key directory ownership and permissions - 09-22-2011
33# - No longer automatically creates default keys on startup (user must now manually
34#   generate keys as privileged user after install) - 08-04-2014
35# - Removed uneeded code from automatic key creation - 12-09-2014
36
37. /etc/rc.d/init.d/functions
38
39prefix=/usr/local
40exec_prefix=${prefix}
41
42RETVAL=0
43prog="opendkim"
44
45DAEMON=${exec_prefix}/sbin/$prog
46CONF_FILE=${prefix}/etc/$prog.conf
47PID_FILE=${prefix}/var/run/$prog/$prog.pid
48
49if [ -f /etc/sysconfig/opendkim ]; then
50	. /etc/sysconfig/opendkim
51fi
52
53start() {
54	echo -n $"Starting OpenDKIM Milter: "
55	if [ -f $PID_FILE ]; then
56		PID=`cat $PID_FILE`
57		echo OpenDKIM already running as pid $PID
58	        exit 2;
59	else
60		daemon $DAEMON -x $CONF_FILE -P $PID_FILE
61		RETVAL=$?
62		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/opendkim
63		echo
64		return $RETVAL
65	fi
66}
67
68stop() {
69	echo -n $"Stopping OpenDKIM Milter: "
70	killproc -p $PID_FILE opendkim
71	RETVAL=$?
72	echo
73	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/opendkim
74	return $RETVAL
75}
76
77restart() {
78	stop
79	start
80}
81
82reload() {
83	echo -n $"Reloading OpenDKIM Milter configuration: "
84	killproc -p $PID_FILE opendkim -SIGUSR1
85	RETVAL=$?
86	echo
87	return $RETVAL
88}
89
90case "$1" in
91  start)
92	start
93	;;
94  stop)
95	stop
96	;;
97  reload)
98	reload
99	;;
100  restart)
101	restart
102	;;
103  status)
104	status -p $PID_FILE opendkim
105	;;
106  condrestart)
107	[ -f /var/lock/subsys/opendkim ] && restart || :
108	;;
109  *)
110	echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
111	exit 1
112esac
113
114exit $?
115