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