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