Home | History | Annotate | Line # | Download | only in scripts
      1 #!/bin/sh
      2 # control starting, stopping, or restarting amd.
      3 # usage: ctl-amd [start|stop|status|restart|condrestart|reload]
      4 #
      5 # Package:	am-utils-6.x
      6 # Author:	Erez Zadok <ezk (at] cs.columbia.edu>
      7 #
      8 # chkconfig: - 72 28
      9 # description: Runs the automount daemon that mounts devices and NFS hosts \
     10 #              on demand.
     11 # processname: amd
     12 # config: /etc/amd.conf
     13 #
     14 
     15 # set path
     16 prefix=@prefix@
     17 exec_prefix=@exec_prefix@
     18 PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH}
     19 export PATH
     20 
     21 # kill the named process(es)
     22 killproc()
     23 {
     24 # first try to get PID via an amq RPC
     25 pid=`amq -p 2>/dev/null`
     26 if test "$pid" != ""
     27 then
     28 	kill $pid
     29 	return 0
     30 fi
     31 
     32 # try bsd style ps
     33 pscmd="ps axc"
     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 bsd44 style ps
     42 pscmd="ps -x"
     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 # try svr4 style ps
     51 pscmd="ps -e"
     52 pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
     53 if test "$pid" != ""
     54 then
     55 	kill $pid
     56 	return 0
     57 fi
     58 
     59 # failed
     60 return 1
     61 }
     62 
     63 # before running any real programs, chdir to / to avoid possible hangs on
     64 # (NFS) mounts which may be restarting.
     65 cd /
     66 
     67 # search for amd.conf file
     68 CF_FILE="@sysconfdir@/amd.conf"
     69 # any local copy of the conf file overrides the "global" one
     70 if [ -f /etc/amd.conf ]
     71 then
     72 	CF_FILE="/etc/amd.conf"
     73 fi
     74 if [ -f @sysconfdir@/amd.conf ]
     75 then
     76 	CF_FILE="@sysconfdir@/amd.conf"
     77 fi
     78 if [ -f /etc/local/amd.conf ]
     79 then
     80 	CF_FILE="/etc/local/amd.conf"
     81 fi
     82 
     83 # if have the directory /tftpboot/.amd, then add a tag to include it
     84 CF_TAG=""
     85 if [ -d /tftpboot/.amd ]
     86 then
     87 	CF_TAG="-T tftpboot"
     88 fi
     89 
     90 case "$1" in
     91 'start')
     92 	# Start the amd automounter.
     93 	if [ -x @sbindir@/amd ]
     94 	then
     95 		# do not specify full path of amd so killproc() works
     96 		amd -F $CF_FILE $CF_TAG
     97 		test -x /var/lock/subsys && touch /var/lock/subsys/amd
     98 	fi
     99 	;;
    100 
    101 'stop')
    102 	# prepend space to program name to ensure only amd process dies
    103 	echo "killing amd..."
    104 	killproc " amd"
    105 	wait4amd2die
    106 	rm -f /var/lock/subsys/amd
    107 	;;
    108 
    109 'restart')
    110 	# kill amd, wait for it to die, then restart
    111 	ctl-amd stop
    112 	if [ $? != 0 ]
    113 	then
    114 		echo "NOT restarting amd!"
    115 	else
    116 		echo "Restarting amd..."
    117 		sleep 1
    118 		ctl-amd start
    119 	fi
    120 	;;
    121 
    122 'condrestart')
    123      if [ -f /var/lock/subsys/amd ]; then
    124             ctl-amd stop
    125             ctl-amd start
    126         fi
    127      ;;
    128 
    129 'reload')
    130         amq -f
    131         ;;
    132 
    133 'status')
    134 	# run amq -v to produce status
    135 	pid=`amq -p 2>/dev/null`
    136 	if [ $? = 0 ]
    137 	then
    138 		echo "amd (pid $pid) is running..."
    139 	else
    140 		echo "amd is stopped"
    141 	fi
    142 	;;
    143 
    144 # start_msg and stop_msg are for HPUX
    145 'start_msg')
    146 	echo "Start am-utils 6.1 automounter"
    147 	;;
    148 'stop_msg')
    149 	echo "Stop am-utils 6.1 automounter"
    150 	;;
    151 
    152 *)
    153 	echo "Usage: $0 [start|stop|status|restart|condrestart|reload]"
    154 	;;
    155 esac
    156