Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / contrib / amd / scripts / ctl-amd.in
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: - 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
16 prefix=@prefix@
17 exec_prefix=@exec_prefix@
18 PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH}
19 export PATH
20
21 # kill the named process(es)
22 killproc()
23 {
24 # first try to get PID via an amq RPC
25 pid=`amq -p 2>/dev/null`
26 if test "$pid" != ""
27 then
28         kill $pid
29         return 0
30 fi
31
32 # try bsd style ps
33 pscmd="ps axc"
34 pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
35 if test "$pid" != ""
36 then
37         kill $pid
38         return 0
39 fi
40
41 # try bsd44 style ps
42 pscmd="ps -x"
43 pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
44 if test "$pid" != ""
45 then
46         kill $pid
47         return 0
48 fi
49
50 # try svr4 style ps
51 pscmd="ps -e"
52 pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^  *//' -e 's/ .*//'`
53 if test "$pid" != ""
54 then
55         kill $pid
56         return 0
57 fi
58
59 # failed
60 return 1
61 }
62
63 # search for amd.conf file
64 CF_FILE="${prefix}/etc/amd.conf"
65 # any local copy of the conf file overrides the "global" one
66 if [ -f /etc/amd.conf ]
67 then
68         CF_FILE="/etc/amd.conf"
69 fi
70 if [ -f ${prefix}/etc/amd.conf ]
71 then
72         CF_FILE="${prefix}/etc/amd.conf"
73 fi
74 if [ -f /etc/local/amd.conf ]
75 then
76         CF_FILE="/etc/local/amd.conf"
77 fi
78
79 # if have the directory /tftpboot/.amd, then add a tag to include it
80 CF_TAG=""
81 if [ -d /tftpboot/.amd ]
82 then
83         CF_TAG="-T tftpboot"
84 fi
85
86 case "$1" in
87 'start')
88         #
89         # Start the amd automounter.
90         #
91         if [ -x @sbindir@/amd ]
92         then
93                 # do not specify full path of amd so killproc() works
94                 amd -F $CF_FILE $CF_TAG
95         fi
96         ;;
97
98 'stop')
99         # prepend space to program name to ensure only amd process dies
100         echo "killing amd..."
101         killproc " amd"
102         wait4amd2die
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 *)
119         echo "Usage: @sbindir@/ctl-amd [ start | stop | restart ]"
120         ;;
121 esac