File: am-utils.init

package info (click to toggle)
am-utils 6.1.5-12
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 10,004 kB
  • ctags: 8,779
  • sloc: ansic: 39,266; sh: 10,560; perl: 2,429; makefile: 875; lex: 466; yacc: 349
file content (216 lines) | stat: -rw-r--r-- 4,414 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#! /bin/sh

#  Copyright (C) 2004-2008 Tim Cutts <timc@chiark.greenend.org.uk>
#  Copyright (C) 2001-2003 Philippe Troin <phil@fifi.org>
#  Copyright (C) 1996-98 by Dominik Kubla, <kubla@Uni-Mainz.DE> and
#                        Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
#

### BEGIN INIT INFO
# Provides:          am-utils
# Required-Start:    $portmap $local_fs
# Required-Stop:     $portmap $local_fs
# Should-Start:      nis
# Should-Stop:       nis
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: BSD automounter
# Description:       Automount local and remote filesystems
### END INIT INFO

PATH=/usr/sbin:/sbin:/usr/bin:/bin
export PATH

# Defaults
CONF=/etc/default/am-utils

# If the package is removed, skip it.
test -x /usr/sbin/amd || exit 0

get_amd_args() {
    if [ ! -f "$CONF" ]
    then
	echo "$0: not configured yet (try running \"dpkg-reconfigure am-utils\")." 1>&2
	exit 1
    fi
    . "$CONF"

    if test "$AM_UTILS_USE_NIS" = true
    then
	map="$AM_UTILS_NIS_MASTER_MAP"
	case "$AM_UTILS_NIS_MASTER_MAP_KEY_STYLE" in
	    config)
		key="$AM_UTILS_NIS_KEY"
		AMDARGS="`ypmatch \"$key\" \"$map\"`"
		;;
	    onekey)
		AMDARGS="`ypcat \"$map\"`"
		;;
	    mountpoint)
		AMDARGS="`ypcat -k \"$map\"`"
		;;
	    custom)
		AMDARGS="`sh -c \"$AM_UTILS_NIS_CUSTOM\"`"
		;;
	    *)
		echo "$0: bad key style"
		exit 1
		;;
	esac
	if [ -z "$AMDARGS" ]
	then
	    echo "$0: cannot find master map" 1>&2
	    exit 1
	fi
    else
	AMDARGS=""

	if [ "$AM_UTILS_MAP_NET" = true ]
	then
	    AMDARGS="$AMDARGS /net /usr/share/am-utils/amd.net"
	fi

	if [ "$AM_UTILS_MAP_HOME" = true ]
	then
	    AMDARGS="$AMDARGS /home /etc/passwd"
	fi

	AMDARGS="$AMDARGS $AM_UTILS_MAP_OTHERS"
    fi

    if  [ "$AM_UTILS_CLUSTERNAME" != "" ]; then
        AMDARGS="-C \"$AM_UTILS_CLUSTERNAME\" $AMDARGS"
    fi

}

start_amd() {
    pid="`amq -p 2>/dev/null`"
    if [ -n "$pid" ]; then
	echo "Starting automounter: amd is already running" 1>&2
	exit 1
    fi

    # If the hostname is not a FQHN, add the -d command line switch,
    # so that hostnames in the maps are stripped correctly.
    case `hostname` in
	*.*)	dnsdomain=''
		;;
	*)	if test "$AM_UTILS_USE_NIS" = true; then
	          dnsdomainname=`dnsdomainname`
		  if [ "$dnsdomainname" ] ; then
		    dnsdomain="-d $dnsdomainname"
		  else
		    echo "$0: please setup your domainname" 1>&2
		    exit 1
		  fi
		else
		  dnsdomain=''
		fi
		;;
    esac

    get_amd_args

    echo -n "Starting automounter: amd"
    /usr/sbin/amd -F /etc/am-utils/amd.conf $dnsdomain $AMDARGS
    echo "."
}

raze_amd() {
  # This function tries to kill an amd which hasn't exited nicely.
  # This happens really easily, especially if using mount_type autofs

  # Get the currently mounted filesystems
  filesystems=`/bin/tempfile -s .amd`
  if [ $? -ne 0 ]; then
    return 1
  fi

  amq | awk '$2 !~ "root" {print $1}' > $filesystems

  # Kill the daemon
  kill -9 "$pid"

  sleep 10

  if kill -s 0 $pid; then
    rm -f $filesystems
    return 1
  fi

  # Attempt to forcibly unmount the remaining filesystems
  returncode=0
  tac $filesystems | while read fs; do
    umount -f "$fs" || returncode=1
    sleep 1
  done

  rm -f $filesystems
  return $returncode
}

stop_amd() {
    pid="`amq -p 2>/dev/null`"
    if [ -z "$pid" ]; then
	echo "Stopping automounter: amd not running" 1>&2
	if [ $# -eq 0 ]
	then
	    exit 1
	else
	    return
	fi
    fi
    echo -n "Requesting amd unmount filesystems: "
    amq | awk '{print $1}' | tac | xargs -n 1 amq -u
    echo " done."
    echo -n "Stopping automounter: amd "
    kill -s TERM "$pid"
    # wait until amd has finished; this may take a little bit, and amd can't
    # start while an old one is running
    i=0
    maxsecs=120
    while [ $i -le $maxsecs ] && kill -s 0 $pid >/dev/null 2>&1; do
	echo -n "."
	sleep 1
	i="`expr $i + 1`"
	[ $i -eq 15 ] && echo -n " [will wait `expr $maxsecs - $i` secs more] "
    done
    if kill -s 0 $pid >/dev/null 2>&1
    then
	if raze_amd; then
	  echo " done."
	else
	  echo " failed."
	  exit 1
	fi
    else
	echo " done."
    fi
}

case "$1" in
  start)
	start_amd
	;;

  stop)
	stop_amd
	;;


  restart|force-reload)
	stop_amd -noquit
	start_amd
	;;

  reload)
	# amd tests itself if its map files have changed, so nothing to do here
	;;

  *)
	echo "Usage: /etc/init.d/amd {start|stop|restart|[force-]reload}"
	exit 1
esac

exit 0