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