]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/amd/scripts/ctl-hlfsd.in
This commit was generated by cvs2svn to compensate for changes in r147460,
[FreeBSD/FreeBSD.git] / contrib / amd / scripts / ctl-hlfsd.in
1 #!/bin/sh
2 # control starting, stopping, or restarting hlfsd.
3 # usage: ctl-hlfsd [start | stop | restart]
4 #
5 # Package:      am-utils-6.0
6 # Author:       Erez Zadok <ezk@cs.columbia.edu>
7 #
8 # chkconfig: - 72 28
9 # description: hlfsd is a daemon similar to amd, used to redirect user
10 #              mail to home directory of the user
11 # processname: hlfsd
12 #
13
14 # set path
15 prefix=@prefix@
16 exec_prefix=@exec_prefix@
17 PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH}
18 export PATH
19
20 # kill the named process(es)
21 killproc()
22 {
23 # try bsd style ps
24 pscmd="ps axc"
25 pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
26 if test "$pid" != ""
27 then
28         kill $pid
29         return 0
30 fi
31
32 # try bsd44 style ps
33 pscmd="ps -x"
34 pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
35 if test "$pid" != ""
36 then
37         kill $pid
38         return 0
39 fi
40
41 # try svr4 style ps
42 pscmd="ps -e"
43 pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
44 if test "$pid" != ""
45 then
46         kill $pid
47         return 0
48 fi
49
50 # failed
51 return 1
52 }
53
54 # locate logs directory
55 if [ -d /var/log ]; then
56         logdir="/var/log"
57 else
58         logdir="/tmp"
59 fi
60
61 # locate the mail spool directory
62 if [ -d /var/mail/. ]; then
63         maildir="/var/mail"
64         altmaildir="/var/alt_mail"
65 elif [ -d /var/spool/mail/. ]; then
66         maildir="/var/spool/mail"
67         altmaildir="/var/spool/alt_mail"
68 else
69         maildir="/usr/spool/mail"
70         altmaildir="/usr/spool/alt_mail"
71 fi
72
73 # locate any optional password file
74 if [ -f ${prefix}/etc/passwd ]; then
75         PASSWD_FILE="-P ${prefix}/etc/passwd"
76 else
77         PASSWD_FILE=""
78 fi
79
80 case "$1" in
81 'start')
82         #
83         # Start the hlfsd mail redirector service
84         #
85         if [ -x @sbindir@/hlfsd -a -h $maildir ]
86         then
87                 echo @sbindir@/hlfsd ${PASSWD_FILE} -a $altmaildir -x all -D fork -l $logdir/hlfsd /mail/home .mailspool
88                 @sbindir@/hlfsd ${PASSWD_FILE} -a $altmaildir -x all -D fork -l $logdir/hlfsd /mail/home .mailspool &
89                 test -x /var/lock/subsys && touch /var/lock/subsys/hlfsd
90         fi
91         ;;
92
93 'stop')
94         # prepend space to program name to ensure only amd process dies
95         killproc " hlfsd"
96         test -f /var/lock/subsys/hlfsd && rm -f /var/lock/subsys/hlfsd
97         ;;
98
99 'restart')
100         # kill hlfsd, wait for it to die, then restart
101         echo "killing hlfsd..."
102         ctl-hlfsd stop
103         echo "Waiting for 10 seconds..."
104         sleep 10        # hope that would be enough
105         echo "Restarting hlfsd..."
106         ctl-hlfsd start
107         ;;
108
109 *)
110         echo "Usage: @sbindir@/ctl-hlfsd [ start | stop | restart ]"
111         ;;
112 esac