summaryrefslogtreecommitdiff
path: root/debian/exim4-base.init
blob: b7aeb4a422dee28fa91a4b6bc4c280dba7732113 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#! /bin/sh
# /etc/init.d/exim4
#
# Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for exim by Tim Cutts <timc@chiark.greenend.org.uk>
# Modified for exim4 by Andreas Metzler <ametzler@downhill.at.eu.org>

set -e

upex4conf() {
  UPEX4CONF="update-exim4.conf"
  OLDIFS="$IFS"
  IFS=:
  for p in $PATH; do
   if [ -x "$p/$UPEX4CONF" ]; then
     IFS="$OLDIFS"
     $p/$UPEX4CONF
     return 0
   fi
  done
  IFS="$OLDIFS"
}
														       
# Exit if exim runs from /etc/inetd.conf
if [ -f /etc/inetd.conf ] && grep -E -q "^ *([0-9.]+:)?smtp" /etc/inetd.conf; then
    upex4conf
    exit 0
fi


DAEMON=/usr/sbin/exim4
NAME=exim4

##test -x $DAEMON || exit 0
test -x /usr/lib/exim4/exim4 || exit 0

#read default file
QUEUERUNNER='combined'
QUEUEINTERVAL='30m'
[ -f /etc/default/exim4 ] && . /etc/default/exim4

start_exim()
{
	case ${QUEUERUNNER} in
		combined)
			start-stop-daemon --start --pidfile /var/run/exim4/exim.pid \
				--exec $DAEMON -- -bd -q${QFLAGS}${QUEUEINTERVAL} \
				${COMMONOPTIONS} ${QUEUERUNNEROPTIONS} ${SMTPLISTENEROPTIONS}
			;;
		separate)
			start-stop-daemon --start --pidfile /var/run/exim4/exim.pid \
				--exec $DAEMON -- -bd ${SMTPLISTENEROPTIONS} ${COMMONOPTIONS}
			start-stop-daemon --start --pidfile /var/run/exim4/eximqr.pid \
				--exec $DAEMON -- -oP /var/run/exim4/eximqr.pid \
				-q${QFLAGS}${QUEUEINTERVAL} ${QUEUERUNNEROPTIONS} ${COMMONOPTIONS}
			;;
		no)
			start-stop-daemon --start --pidfile /var/run/exim4/exim.pid \
				--exec $DAEMON -- -bd ${SMTPLISTENEROPTIONS}
			;;
	esac
}

stop_exim()
{
# we try to kill eximqr and exim SMTP listener, no matter what ${QUEUERUNNER} is
# set to, we could have switched since starting.
	[ -f /var/run/exim4/eximqr.pid ] && \
		start-stop-daemon --stop --pidfile /var/run/exim4/eximqr.pid \
			--oknodo --retry 30 --exec $DAEMON
	[ -f /var/run/exim4/exim.pid ] && \
		start-stop-daemon --stop --pidfile /var/run/exim4/exim.pid \
			--oknodo --retry 30 --exec $DAEMON
	rm -f /var/run/exim4/eximqr.pid /var/run/exim4/exim.pid 
}

reload_exim()
{
	case ${QUEUERUNNER} in
		combined|no)
			start-stop-daemon --stop --pidfile /var/run/exim4/exim.pid \
				--signal 1 --exec $DAEMON
			;;
		separate)
			start-stop-daemon --stop --pidfile /var/run/exim4/exim.pid \
				--signal 1 --exec $DAEMON
			start-stop-daemon --stop --pidfile /var/run/exim4/eximqr.pid \
				--signal 1 --exec $DAEMON
			;;
	esac	
}
		

# check for valid configuration file
isconfigvalid()
{
if ! $DAEMON -bV > /dev/null ; then
  echo
  echo "Warning! Invalid configuration file for $NAME. Exiting." 1>&2
  exit 1
fi
}

case "$1" in
  start)
    echo -n "Starting MTA: "
    # regenerate exim4.conf
    upex4conf
    isconfigvalid
    start_exim
    echo "$NAME."
    ;;
  stop)
    echo -n "Stopping MTA: "
    stop_exim
    echo "$NAME."
      ;;
  restart)
    echo -n "Restarting MTA: "
    # regenerate exim4.conf
    upex4conf
    isconfigvalid
    stop_exim
    sleep 2
    start_exim
    echo "$NAME."
    ;;
  reload|force-reload)
    echo "Reloading $NAME configuration files"
    # regenerate exim4.conf
    upex4conf
    isconfigvalid
    reload_exim
    ;;
  status)
    exiwhat
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|reload|status}"
    exit 1
    ;;
esac

exit 0