138494Sobrien#!/bin/sh 238494Sobrien# control starting, stopping, or restarting amd. 382794Sobrien# usage: ctl-amd [start|stop|status|restart|condrestart|reload] 438494Sobrien# 5174294Sobrien# Package: am-utils-6.x 638494Sobrien# Author: Erez Zadok <ezk@cs.columbia.edu> 742629Sobrien# 851292Sobrien# chkconfig: - 72 28 951292Sobrien# description: Runs the automount daemon that mounts devices and NFS hosts \ 10174294Sobrien# on demand. 1151292Sobrien# processname: amd 1251292Sobrien# config: /etc/amd.conf 1351292Sobrien# 1438494Sobrien 1538494Sobrien# set path 1638494Sobrienprefix=@prefix@ 1738494Sobrienexec_prefix=@exec_prefix@ 1838494SobrienPATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH} 1938494Sobrienexport PATH 2038494Sobrien 2138494Sobrien# kill the named process(es) 2238494Sobrienkillproc() 2338494Sobrien{ 2438494Sobrien# first try to get PID via an amq RPC 2538494Sobrienpid=`amq -p 2>/dev/null` 2638494Sobrienif test "$pid" != "" 2738494Sobrienthen 2838494Sobrien kill $pid 2938494Sobrien return 0 3038494Sobrienfi 3138494Sobrien 3238494Sobrien# try bsd style ps 3338494Sobrienpscmd="ps axc" 3438494Sobrienpid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^ *//' -e 's/ .*//'` 3538494Sobrienif test "$pid" != "" 3638494Sobrienthen 3738494Sobrien kill $pid 3838494Sobrien return 0 3938494Sobrienfi 4038494Sobrien 4138494Sobrien# try bsd44 style ps 4238494Sobrienpscmd="ps -x" 4338494Sobrienpid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^ *//' -e 's/ .*//'` 4438494Sobrienif test "$pid" != "" 4538494Sobrienthen 4638494Sobrien kill $pid 4738494Sobrien return 0 4838494Sobrienfi 4938494Sobrien 5038494Sobrien# try svr4 style ps 5138494Sobrienpscmd="ps -e" 5238494Sobrienpid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^ *//' -e 's/ .*//'` 5338494Sobrienif test "$pid" != "" 5438494Sobrienthen 5538494Sobrien kill $pid 5638494Sobrien return 0 5738494Sobrienfi 5838494Sobrien 5938494Sobrien# failed 6038494Sobrienreturn 1 6138494Sobrien} 6238494Sobrien 63174294Sobrien# before running any real programs, chdir to / to avoid possible hangs on 64174294Sobrien# (NFS) mounts which may be restarting. 65174294Sobriencd / 66174294Sobrien 6738494Sobrien# search for amd.conf file 68174294SobrienCF_FILE="@sysconfdir@/amd.conf" 6938494Sobrien# any local copy of the conf file overrides the "global" one 7038494Sobrienif [ -f /etc/amd.conf ] 7138494Sobrienthen 7238494Sobrien CF_FILE="/etc/amd.conf" 7338494Sobrienfi 74174294Sobrienif [ -f @sysconfdir@/amd.conf ] 7538494Sobrienthen 76174294Sobrien CF_FILE="@sysconfdir@/amd.conf" 7738494Sobrienfi 7838494Sobrienif [ -f /etc/local/amd.conf ] 7938494Sobrienthen 8038494Sobrien CF_FILE="/etc/local/amd.conf" 8138494Sobrienfi 8238494Sobrien 8338494Sobrien# if have the directory /tftpboot/.amd, then add a tag to include it 8438494SobrienCF_TAG="" 8538494Sobrienif [ -d /tftpboot/.amd ] 8638494Sobrienthen 8738494Sobrien CF_TAG="-T tftpboot" 8838494Sobrienfi 8938494Sobrien 9038494Sobriencase "$1" in 9138494Sobrien'start') 9238494Sobrien # Start the amd automounter. 9338494Sobrien if [ -x @sbindir@/amd ] 9438494Sobrien then 9538494Sobrien # do not specify full path of amd so killproc() works 9638494Sobrien amd -F $CF_FILE $CF_TAG 97119679Smbr test -x /var/lock/subsys && touch /var/lock/subsys/amd 9838494Sobrien fi 9938494Sobrien ;; 10038494Sobrien 10138494Sobrien'stop') 10238494Sobrien # prepend space to program name to ensure only amd process dies 10342629Sobrien echo "killing amd..." 10438494Sobrien killproc " amd" 10542629Sobrien wait4amd2die 106174294Sobrien rm -f /var/lock/subsys/amd 10738494Sobrien ;; 10838494Sobrien 10938494Sobrien'restart') 11038494Sobrien # kill amd, wait for it to die, then restart 11138494Sobrien ctl-amd stop 11238494Sobrien if [ $? != 0 ] 11338494Sobrien then 11438494Sobrien echo "NOT restarting amd!" 11538494Sobrien else 11638494Sobrien echo "Restarting amd..." 11751292Sobrien sleep 1 11838494Sobrien ctl-amd start 11938494Sobrien fi 12038494Sobrien ;; 12138494Sobrien 12282794Sobrien'condrestart') 12382794Sobrien if [ -f /var/lock/subsys/amd ]; then 124174294Sobrien ctl-amd stop 125174294Sobrien ctl-amd start 126174294Sobrien fi 12782794Sobrien ;; 12882794Sobrien 12982794Sobrien'reload') 130174294Sobrien amq -f 131174294Sobrien ;; 13282794Sobrien 13382794Sobrien'status') 13482794Sobrien # run amq -v to produce status 13582794Sobrien pid=`amq -p 2>/dev/null` 13682794Sobrien if [ $? = 0 ] 13782794Sobrien then 13882794Sobrien echo "amd (pid $pid) is running..." 13982794Sobrien else 14082794Sobrien echo "amd is stopped" 14182794Sobrien fi 14282794Sobrien ;; 14382794Sobrien 14482794Sobrien# start_msg and stop_msg are for HPUX 14582794Sobrien'start_msg') 146174294Sobrien echo "Start am-utils 6.1 automounter" 14782794Sobrien ;; 14882794Sobrien'stop_msg') 149174294Sobrien echo "Stop am-utils 6.1 automounter" 15082794Sobrien ;; 15182794Sobrien 15238494Sobrien*) 153174294Sobrien echo "Usage: $0 [start|stop|status|restart|condrestart|reload]" 15438494Sobrien ;; 15538494Sobrienesac 156