ctl-amd.in revision 42629
1#!/bin/sh
2# control starting, stopping, or restarting amd.
3# usage: ctl-amd [start | stop | restart]
4#
5# Package:	am-utils-6.0
6# Author:	Erez Zadok <ezk@cs.columbia.edu>
7#
8# chkconfig: 345 72 8
9# description: amd is the Berkeley AutoMount Daemon, used for \
10#              automatic filesystem mounting
11
12# set path
13prefix=@prefix@
14exec_prefix=@exec_prefix@
15PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH}
16export PATH
17
18# kill the named process(es)
19killproc()
20{
21# first try to get PID via an amq RPC
22pid=`amq -p 2>/dev/null`
23if test "$pid" != ""
24then
25	kill $pid
26	return 0
27fi
28
29# try bsd style ps
30pscmd="ps axc"
31pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
32if test "$pid" != ""
33then
34	kill $pid
35	return 0
36fi
37
38# try bsd44 style ps
39pscmd="ps -x"
40pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
41if test "$pid" != ""
42then
43	kill $pid
44	return 0
45fi
46
47# try svr4 style ps
48pscmd="ps -e"
49pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
50if test "$pid" != ""
51then
52	kill $pid
53	return 0
54fi
55
56# failed
57return 1
58}
59
60# search for amd.conf file
61CF_FILE="${prefix}/etc/amd.conf"
62# any local copy of the conf file overrides the "global" one
63if [ -f /etc/amd.conf ]
64then
65	CF_FILE="/etc/amd.conf"
66fi
67if [ -f ${prefix}/etc/amd.conf ]
68then
69	CF_FILE="${prefix}/etc/amd.conf"
70fi
71if [ -f /etc/local/amd.conf ]
72then
73	CF_FILE="/etc/local/amd.conf"
74fi
75
76# if have the directory /tftpboot/.amd, then add a tag to include it
77CF_TAG=""
78if [ -d /tftpboot/.amd ]
79then
80	CF_TAG="-T tftpboot"
81fi
82
83case "$1" in
84'start')
85	#
86	# Start the amd automounter.
87	#
88	if [ -x @sbindir@/amd ]
89	then
90		# do not specify full path of amd so killproc() works
91		amd -F $CF_FILE $CF_TAG
92	fi
93	;;
94
95'stop')
96	# prepend space to program name to ensure only amd process dies
97	echo "killing amd..."
98	killproc " amd"
99	wait4amd2die
100	;;
101
102'restart')
103	# kill amd, wait for it to die, then restart
104	ctl-amd stop
105	if [ $? != 0 ]
106	then
107		echo "NOT restarting amd!"
108	else
109		echo "Restarting amd..."
110		ctl-amd start
111	fi
112	;;
113
114*)
115	echo "Usage: @sbindir@/ctl-amd [ start | stop | restart ]"
116	;;
117esac
118