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