1*a53f50b9Schristos#!/bin/bash 2*a53f50b9Schristos# 3*a53f50b9Schristos# Version: 1.3 4*a53f50b9Schristos# 5*a53f50b9Schristos# chkconfig: - 72 28 6*a53f50b9Schristos# description: Runs the automount daemon that mounts devices and NFS hosts \ 7*a53f50b9Schristos# on demand. 8*a53f50b9Schristos# processname: amd 9*a53f50b9Schristos# config: /etc/amd.conf 10*a53f50b9Schristos# 11*a53f50b9Schristos 12*a53f50b9Schristos# we require the /etc/amd.conf file 13*a53f50b9Schristos[ -f /etc/amd.conf ] || exit 0 14*a53f50b9Schristos[ -f /etc/sysconfig/amd ] || exit 0 15*a53f50b9Schristos 16*a53f50b9Schristos# Source function library. 17*a53f50b9Schristos. /etc/init.d/functions 18*a53f50b9Schristos 19*a53f50b9Schristos# Recover AMDOPTS from /etc/sysconfig/amd. 20*a53f50b9Schristosif [ -f /etc/sysconfig/amd ] ; then 21*a53f50b9Schristos . /etc/sysconfig/amd 22*a53f50b9Schristosfi 23*a53f50b9Schristos 24*a53f50b9SchristosRETVAL=0 25*a53f50b9Schristosprog=amd 26*a53f50b9Schristosprefix=@prefix@ 27*a53f50b9Schristosexec_prefix=@exec_prefix@ 28*a53f50b9Schristosamd=@sbindir@/amd 29*a53f50b9Schristos 30*a53f50b9Schristosstart() { 31*a53f50b9Schristos echo -n "Starting $prog: " 32*a53f50b9Schristos daemon $amd -F /etc/amd.conf $AMDOPTS $OPTIONS $MOUNTPTS 33*a53f50b9Schristos RETVAL=$? 34*a53f50b9Schristos echo 35*a53f50b9Schristos [ $RETVAL = 0 ] && touch /var/lock/subsys/amd 36*a53f50b9Schristos return $RETVAL 37*a53f50b9Schristos} 38*a53f50b9Schristos 39*a53f50b9Schristosstop() { 40*a53f50b9Schristos 41*a53f50b9Schristos echo -n "Stopping $prog: " 42*a53f50b9Schristos # modeled from /usr/sbin/ctl-amd 43*a53f50b9Schristos pid=`/usr/sbin/amq -p 2>/dev/null` 44*a53f50b9Schristos if [ "$pid" = "" ] ; then 45*a53f50b9Schristos # amq -p did not give pid, so try ps 46*a53f50b9Schristos pid=`ps acx 2>/dev/null | grep "amd" | sed -e 's/^ *//' -e 's/ .*//'` 47*a53f50b9Schristos fi 48*a53f50b9Schristos if [ "$pid" = "" ] ; then 49*a53f50b9Schristos failure "amd shutdown pid" 50*a53f50b9Schristos echo 51*a53f50b9Schristos return 1 52*a53f50b9Schristos fi 53*a53f50b9Schristos kill $pid 54*a53f50b9Schristos # and this part is from wait4amd2die 55*a53f50b9Schristos delay=5 56*a53f50b9Schristos count=6 57*a53f50b9Schristos i=1 58*a53f50b9Schristos maxcount=`expr $count + 1` 59*a53f50b9Schristos while [ $i != $maxcount ]; do 60*a53f50b9Schristos # run amq 61*a53f50b9Schristos /usr/sbin/amq > /dev/null 2>&1 62*a53f50b9Schristos if [ $? != 0 ] 63*a53f50b9Schristos then 64*a53f50b9Schristos # amq failed to run (because amd is dead) 65*a53f50b9Schristos success "amd shutdown" 66*a53f50b9Schristos rm -f /var/lock/subsys/amd 67*a53f50b9Schristos echo 68*a53f50b9Schristos return 0 69*a53f50b9Schristos fi 70*a53f50b9Schristos sleep $delay 71*a53f50b9Schristos i=`expr $i + 1` 72*a53f50b9Schristos done 73*a53f50b9Schristos failure "amd shutdown (still up)" 74*a53f50b9Schristos echo 75*a53f50b9Schristos return 1 76*a53f50b9Schristos} 77*a53f50b9Schristos# See how we were called. 78*a53f50b9Schristoscase "$1" in 79*a53f50b9Schristos start) 80*a53f50b9Schristos start 81*a53f50b9Schristos ;; 82*a53f50b9Schristos stop) 83*a53f50b9Schristos stop 84*a53f50b9Schristos ;; 85*a53f50b9Schristos status) 86*a53f50b9Schristos status $amd 87*a53f50b9Schristos ;; 88*a53f50b9Schristos restart) 89*a53f50b9Schristos stop 90*a53f50b9Schristos start 91*a53f50b9Schristos ;; 92*a53f50b9Schristos condrestart) 93*a53f50b9Schristos if [ -f /var/lock/subsys/amd ]; then 94*a53f50b9Schristos stop 95*a53f50b9Schristos start 96*a53f50b9Schristos fi 97*a53f50b9Schristos ;; 98*a53f50b9Schristos reload) 99*a53f50b9Schristos action "Reloading $prog:" killall -HUP $amd 100*a53f50b9Schristos ;; 101*a53f50b9Schristos *) 102*a53f50b9Schristos echo "Usage: $0 {start|stop|restart|reload|condrestart|status}" 103*a53f50b9Schristos exit 1 104*a53f50b9Schristosesac 105*a53f50b9Schristos 106*a53f50b9Schristosexit 0 107