aboutsummaryrefslogtreecommitdiff
path: root/network/dkimproxy/rc.dkimproxy
blob: b2ca4fd4260d2f911e871ecec31ea07a51a9781d (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
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh
#
# Copyright (c) 2005-2007 Messiah College.
#
### BEGIN INIT INFO
# Default-Start:  3 4 5
# Default-Stop:   0 1 2 6
# Description:    Runs dkimproxy
### END INIT INFO

### BEGIN CONFIGURABLE BITS
DKIMPROXYDIR=/usr
DKIMPROXYUSER=dkim
DKIMPROXYGROUP=dkim
### END CONFIGURABLE BITS

### IF YOU MOVE THE CONFIG FILES, CHANGE THIS:
DKIMPROXY_IN_CFG="/etc/dkimproxy/dkimproxy_in.conf"
DKIMPROXY_OUT_CFG="/etc/dkimproxy/dkimproxy_out.conf"

if [ ! '(' -f "$DKIMPROXY_IN_CFG" -o -f "$DKIMPROXY_OUT_CFG" ')' ]; then
	echo "Error: one or both of the following files must be created:" >&2
	echo "$DKIMPROXY_IN_CFG" >&2
	echo "$DKIMPROXY_OUT_CFG" >&2
	exit 1
fi

HOSTNAME=`hostname -f`
DKIMPROXY_IN_ARGS="
	--hostname=$HOSTNAME
	--conf_file=$DKIMPROXY_IN_CFG"
DKIMPROXY_OUT_ARGS="
	--conf_file=$DKIMPROXY_OUT_CFG"

DKIMPROXY_COMMON_ARGS="
	--user=$DKIMPROXYUSER
	--group=$DKIMPROXYGROUP
	--daemonize"

DKIMPROXY_IN_BIN="$DKIMPROXYDIR/bin/dkimproxy.in"
DKIMPROXY_OUT_BIN="$DKIMPROXYDIR/bin/dkimproxy.out"

PIDDIR=/var/run/dkimproxy
DKIMPROXY_IN_PID=$PIDDIR/dkimproxy_in.pid
DKIMPROXY_OUT_PID=$PIDDIR/dkimproxy_out.pid

case "$1" in
	start-in)
		echo -n "Starting inbound DKIM-proxy (dkimproxy.in)..."

		# create directory for pid files if necessary
		test -d $PIDDIR || mkdir -p $PIDDIR || exit 1

		# start the daemon
		$DKIMPROXY_IN_BIN $DKIMPROXY_COMMON_ARGS --pidfile=$DKIMPROXY_IN_PID $DKIMPROXY_IN_ARGS
		RETVAL=$?
		if [ $RETVAL -eq 0 ]; then
			echo done.
		else
			echo failed.
			exit $RETVAL
		fi
		;;

	start-out)
		echo -n "Starting outbound DKIM-proxy (dkimproxy.out)..."

		# create directory for pid files if necessary
		test -d $PIDDIR || mkdir -p $PIDDIR || exit 1

		# start the daemon
		$DKIMPROXY_OUT_BIN $DKIMPROXY_COMMON_ARGS --pidfile=$DKIMPROXY_OUT_PID $DKIMPROXY_OUT_ARGS
		RETVAL=$?
		if [ $RETVAL -eq 0 ]; then
			echo done.
		else
			echo failed.
			exit $RETVAL
		fi
		;;

	start)
		test -f $DKIMPROXY_IN_CFG && $0 start-in || exit $?
		test -f $DKIMPROXY_OUT_CFG && $0 start-out || exit $?
		;;

	stop-in)
		echo -n "Shutting down inbound DKIM-proxy (dkimproxy.in)..."
		if [ -f $DKIMPROXY_IN_PID ]; then
			kill `cat $DKIMPROXY_IN_PID` && rm -f $DKIMPROXY_IN_PID
			RETVAL=$?
			[ $RETVAL -eq 0 ] && echo done. || echo failed.
			exit $RETVAL
		else
			echo not running.
		fi
		;;

	stop-out)
		echo -n "Shutting down outbound DKIM-proxy (dkimproxy.out)..."
		if [ -f $DKIMPROXY_OUT_PID ]; then
			kill `cat $DKIMPROXY_OUT_PID` && rm -f $DKIMPROXY_OUT_PID
			RETVAL=$?
			[ $RETVAL -eq 0 ] && echo done. || echo failed.
			exit $RETVAL
		else
			echo not running.
		fi
		;;

	stop)
		test -f $DKIMPROXY_IN_CFG && $0 stop-in || exit $?
		test -f $DKIMPROXY_OUT_CFG && $0 stop-out || exit $?
		;;

	restart)
		$0 stop && $0 start || exit $?
		;;

	status-in)
		echo -n "dkimproxy.in..."
		if [ -f $DKIMPROXY_IN_PID ]; then
			pid=`cat $DKIMPROXY_IN_PID`
			if ps -ef |grep -v grep |grep -q "$pid"; then
				echo " running (pid=$pid)"
			else
				echo " stopped (pid=$pid not found)"
			fi
		else
			echo " stopped"
		fi
		;;

	status-out)
		echo -n "dkimproxy.out..."
		if [ -f $DKIMPROXY_OUT_PID ]; then
			pid=`cat $DKIMPROXY_OUT_PID`
			if ps -ef |grep -v grep |grep -q "$pid"; then
				echo " running (pid=$pid)"
			else
				echo " stopped (pid=$pid not found)"
			fi
		else
			echo " stopped"
		fi
		;;

	status)
		test -f $DKIMPROXY_IN_CFG && $0 status-in || exit $?
		test -f $DKIMPROXY_OUT_CFG && $0 status-out || exit $?
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 1
		;;
esac