File: opendmarc.init

package info (click to toggle)
opendmarc 1.3.0%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,480 kB
  • ctags: 913
  • sloc: xml: 19,673; ansic: 12,748; sh: 10,976; perl: 2,060; makefile: 194; python: 58
file content (151 lines) | stat: -rw-r--r-- 3,416 bytes parent folder | download | duplicates (5)
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
#! /bin/sh
#
### BEGIN INIT INFO
# Provides:		opendmarc
# Required-Start:	$syslog $time $local_fs $remote_fs $named $network
# Required-Stop:	$syslog $time $local_fs $remote_fs
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Start the OpenDMARC service
# Description:		Enable DMAR verification and reporting provided by OpenDMARC
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/opendmarc
NAME=opendmarc
DESC="OpenDMARC"
RUNDIR=/var/run/$NAME
USER=opendmarc
GROUP=opendmarc
SOCKET=local:$RUNDIR/$NAME.sock
PIDFILE=$RUNDIR/$NAME.pid

# How long to wait for the process to die on stop/restart
stoptimeout=5

test -x $DAEMON || exit 0

# Include LSB provided init functions
. /lib/lsb/init-functions

# Include opendkim defaults if available
if [ -f /etc/default/opendmarc ] ; then
	. /etc/default/opendmarc
fi

if [ -f /etc/opendmarc.conf ]; then
	CONFIG_SOCKET=`awk '$1 == "Socket" { print $2 }' /etc/opendmarc.conf`
fi

# This can be set via Socket option in config file, so it's not required
if [ -n "$SOCKET" -a -z "$CONFIG_SOCKET" ]; then
	DAEMON_OPTS="-p $SOCKET $DAEMON_OPTS"
fi

DAEMON_OPTS="-c /etc/opendmarc.conf -u $USER -P $PIDFILE $DAEMON_OPTS"

start() {
	# Create the run directory if it doesn't exist
	if [ ! -d "$RUNDIR" ]; then
		install -o "$USER" -g "$GROUP" -m 755 -d "$RUNDIR" || return 2
		[ -x /sbin/restorecon ] && /sbin/restorecon "$RUNDIR"
	fi
	# Clean up stale sockets
	if [ -f "$PIDFILE" ]; then
		pid=`cat $PIDFILE`
		if ! ps -C "$DAEMON" -s "$pid" >/dev/null; then
			rm "$PIDFILE"
			TMPSOCKET=""
			if [ -n "$SOCKET" ]; then
				TMPSOCKET="$SOCKET"
			elif [ -n "$CONFIG_SOCKET" ]; then
				TMPSOCKET="$CONFIG_SOCKET"
			fi
			if [ -n "$TMPSOCKET" ]; then
				# UNIX sockets may be specified with or without the
				# local: prefix; handle both
				t=`echo $SOCKET | cut -d: -f1`
				s=`echo $SOCKET | cut -d: -f2`
				if [ -e "$s" -a -S "$s" ]; then
					if [ "$t" = "$s" -o "$t" = "local" ]; then
						rm "$s"
					fi
				fi
			fi
		fi
	fi
	start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" --test -- $DAEMON_OPTS || return 1
	start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" -- $DAEMON_OPTS || return 2
}

stop() {
	start-stop-daemon --stop --retry "$stoptimeout" --exec "$DAEMON"
	[ "$?" = 2 ] && return 2
}

reload() {
	start-stop-daemon --stop --signal USR1 --exec "$DAEMON"
}

status() {
    local pidfile daemon name status

    pidfile=
    OPTIND=1
    while getopts p: opt ; do
        case "$opt" in
            p)  pidfile="$OPTARG";;
        esac
    done
    shift $(($OPTIND - 1))

    if [ -n "$pidfile" ]; then
        pidfile="-p $pidfile"
    fi
    daemon="$1"
    name="$2"

    status="0"
    pidofproc $pidfile $daemon >/dev/null || status="$?"
    if [ "$status" = 0 ]; then
        log_success_msg "$name is running"
        return 0
    else
        log_failure_msg "$name is not running"
        return $status
    fi
}

case "$1" in
  start)
	echo -n "Starting $DESC: "
	start
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	stop
	echo "$NAME."
	;;
  restart)
	echo -n "Restarting $DESC: "
	stop
	start
	echo "$NAME."
	;;
  reload|force-reload)
	echo -n "Restarting $DESC: "
	reload
	echo "$NAME."
	;;
  status)
	status $DAEMON $NAME
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
	exit 1
	;;
esac

exit 0