diff options
Diffstat (limited to 'contrib/amd/scripts/ctl-amd.in')
-rwxr-xr-x | contrib/amd/scripts/ctl-amd.in | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/contrib/amd/scripts/ctl-amd.in b/contrib/amd/scripts/ctl-amd.in new file mode 100755 index 0000000..665a7dd --- /dev/null +++ b/contrib/amd/scripts/ctl-amd.in @@ -0,0 +1,113 @@ +#!/bin/sh +# control starting, stopping, or restarting amd. +# usage: ctl-amd [start | stop | restart] +# +# Package: am-utils-6.0 +# Author: Erez Zadok <ezk@cs.columbia.edu> + +# set path +prefix=@prefix@ +exec_prefix=@exec_prefix@ +PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH} +export PATH + +# kill the named process(es) +killproc() +{ +# first try to get PID via an amq RPC +pid=`amq -p 2>/dev/null` +if test "$pid" != "" +then + kill $pid + return 0 +fi + +# try bsd style ps +pscmd="ps axc" +pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^ *//' -e 's/ .*//'` +if test "$pid" != "" +then + kill $pid + return 0 +fi + +# try bsd44 style ps +pscmd="ps -x" +pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^ *//' -e 's/ .*//'` +if test "$pid" != "" +then + kill $pid + return 0 +fi + +# try svr4 style ps +pscmd="ps -e" +pid=`${pscmd} 2>/dev/null | grep "$1" | sed -e 's/^ *//' -e 's/ .*//'` +if test "$pid" != "" +then + kill $pid + return 0 +fi + +# failed +return 1 +} + +# search for amd.conf file +CF_FILE="${prefix}/etc/amd.conf" +# any local copy of the conf file overrides the "global" one +if [ -f /etc/amd.conf ] +then + CF_FILE="/etc/amd.conf" +fi +if [ -f ${prefix}/etc/amd.conf ] +then + CF_FILE="${prefix}/etc/amd.conf" +fi +if [ -f /etc/local/amd.conf ] +then + CF_FILE="/etc/local/amd.conf" +fi + +# if have the directory /tftpboot/.amd, then add a tag to include it +CF_TAG="" +if [ -d /tftpboot/.amd ] +then + CF_TAG="-T tftpboot" +fi + +case "$1" in +'start') + # + # Start the amd automounter. + # + if [ -x @sbindir@/amd ] + then + # do not specify full path of amd so killproc() works + amd -F $CF_FILE $CF_TAG + fi + ;; + +'stop') + # prepend space to program name to ensure only amd process dies + killproc " amd" + ;; + +'restart') + # kill amd, wait for it to die, then restart + echo "killing amd..." + ctl-amd stop + wait4amd2die + if [ $? != 0 ] + then + echo "NOT restarting amd!" + else + echo "Restarting amd..." + ctl-amd start + fi + ;; + +*) + echo "Usage: @sbindir@/ctl-amd [ start | stop | restart ]" + ;; +esac |