summaryrefslogtreecommitdiffstats
path: root/contrib/amd/scripts/ctl-hlfsd.in
blob: ee0dd27ca15a99c3c4dd756cc9725de6433e63b0 (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
#!/bin/sh
# control starting, stopping, or restarting hlfsd.
# usage: ctl-hlfsd [start | stop | restart]
#
# Package:	am-utils-6.x
# Author:	Erez Zadok <ezk@cs.columbia.edu>
#
# chkconfig: - 72 28
# description: hlfsd is a daemon similar to amd, used to redirect user
#              mail to home directory of the user
# processname: hlfsd
#

# set path
prefix=@prefix@
exec_prefix=@exec_prefix@
PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH}
export PATH

# kill the named process(es)
killproc()
{
# try bsd style ps
pscmd="ps axc"
pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
if test "$pid" != ""
then
	kill $pid
	return 0
fi

# try bsd44 style ps
pscmd="ps -x"
pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
if test "$pid" != ""
then
	kill $pid
	return 0
fi

# try svr4 style ps
pscmd="ps -e"
pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
if test "$pid" != ""
then
	kill $pid
	return 0
fi

# failed
return 1
}

# before running any real programs, chdir to / to avoid possible hangs on (NFS)
# mounts.
cd /

# locate logs directory
if [ -d /var/log ]; then
	logdir="/var/log"
else
	logdir="/tmp"
fi

# locate the mail spool directory
if [ -d /var/mail/. ]; then
	maildir="/var/mail"
	altmaildir="/var/alt_mail"
elif [ -d /var/spool/mail/. ]; then
	maildir="/var/spool/mail"
	altmaildir="/var/spool/alt_mail"
else
	maildir="/usr/spool/mail"
	altmaildir="/usr/spool/alt_mail"
fi

# locate any optional password file
if [ -f @sysconfdir@/passwd ]; then
	PASSWD_FILE="-P @sysconfdir@/passwd"
else
	PASSWD_FILE=""
fi

case "$1" in
'start')
	#
	# Start the hlfsd mail redirector service
	#
	if [ -x @sbindir@/hlfsd -a -h $maildir ]
	then
		echo @sbindir@/hlfsd ${PASSWD_FILE} -a $altmaildir -x all -l $logdir/hlfsd /mail/home .mailspool
		@sbindir@/hlfsd ${PASSWD_FILE} -a $altmaildir -x all -l $logdir/hlfsd /mail/home .mailspool &
		test -x /var/lock/subsys && touch /var/lock/subsys/hlfsd
	fi
	;;

'stop')
	# prepend space to program name to ensure only amd process dies
	killproc " hlfsd"
	test -f /var/lock/subsys/hlfsd && rm -f /var/lock/subsys/hlfsd
	;;

'restart')
	# kill hlfsd, wait for it to die, then restart
	echo "killing hlfsd..."
	ctl-hlfsd stop
	echo "Waiting for 10 seconds..."
	sleep 10	# hope that would be enough
	echo "Restarting hlfsd..."
	ctl-hlfsd start
	;;

*)
	echo "Usage: @sbindir@/ctl-hlfsd [ start | stop | restart ]"
	;;
esac
OpenPOWER on IntegriCloud