-
Notifications
You must be signed in to change notification settings - Fork 6
/
ppolicy.init
executable file
·134 lines (121 loc) · 3.22 KB
/
ppolicy.init
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
#!/bin/sh
#
# Startup script for a Postfix Policy Twisted service.
#
# chkconfig: 2345 85 15
# description: Start-up script for the Twisted service ppolicy.tap
# processname: ppolicy
# config: /etc/postfix/ppolicy.conf
# pidfile: /var/log/ppolicy/ppolicy.pid
# Source function library.
. /etc/rc.d/init.d/functions
### Default variables
PPOLICY_ACCOUNT="nobody"
SYSCONFIG="/etc/sysconfig/ppolicy"
pidfile=/var/log/ppolicy/ppolicy.pid
rundir=/var/log/ppolicy
tapfile=/usr/sbin/ppolicy.tap
logfile=/var/log/ppolicy/ppolicy.log
twistd=/usr/bin/twistd
statefile=/etc/postfix/ppolicy.state
prog="ppolicy"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
# check for required files
if [ ! -x "$twistd" ]; then
echo "$0: Aborting, no $twistd found"
exit 1
fi
if [ ! -r "$tapfile" ]; then
echo "$0: Aborting, no file $tapfile found."
exit 1
fi
if [ ! -d "${rundir}" ]; then
echo "$0: Aborting, run directory $rundir doesn't exist."
exit 1
fi
if [ `id -u $PPOLICY_ACCOUNT` != `stat --format=%u ${rundir}` ]; then
#echo "$0: Aborting, run directory $rundir owner differs from ppolicy account."
#echo "run \"chown $PPOLICY_ACCOUNT ${rundir}\" if appropriate"
#exit 1
echo "Log/run directory owner "`stat --format=%u ${rundir}`" doesn't match ppolicy account $PPOLICY_ACCOUNT"
echo "Changing ownership for ${rundir} to $PPOLICY_ACCOUNT"
chown $PPOLICY_ACCOUNT ${rundir}
fi
if [ ! -f ${statefile} ]; then
touch ${statefile}
fi
if [ `id -u $PPOLICY_ACCOUNT` != `stat --format=%u ${statefile}` ]; then
echo "State file owner "`stat --format=%u ${statefile}`" doesn't match ppolicy account $PPOLICY_ACCOUNT"
echo "Changing ownership for ${statefile} to $PPOLICY_ACCOUNT"
chown $PPOLICY_ACCOUNT ${statefile}
fi
start() {
# Start daemon
echo -n "Starting $prog (twistd):"
daemon \
--user "$PPOLICY_ACCOUNT" \
$twistd \
--pidfile=$pidfile \
--rundir=$rundir \
--file=$tapfile \
--python=$tapfile \
--no_save \
--logfile=$logfile
retval=$?
echo
# [ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
# Stop daemon
echo -n "Stopping $prog (twistd):"
if [ ! -f ${pidfile} ]; then
failure $"$base shutdown"
return 1
fi
pid=`cat "${pidfile}"`
if checkpid $pid 2>&1; then
# TERM first, then KILL if not dead
kill -TERM $pid >/dev/null 2>&1
usleep 100000
if checkpid $pid && sleep 1 &&
checkpid $pid && sleep 3 &&
checkpid $pid ; then
kill -KILL $pid >/dev/null 2>&1
usleep 100000
fi
fi
checkpid $pid
retval=$?
[ "$retval" -eq 0 ] && failure $"$base shutdown" || success $"$base shutdown"
echo
# [ $retval -eq 0 ] && rm -f $lockfile
retval=$((! $retval))
return $retval
}
restart() {
# Restart daemon
stop
sleep 1
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
exit $?