~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/am-utils

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh
2
 
 
3
 
#  Copyright (C) 2004-2008 Tim Cutts <timc@chiark.greenend.org.uk>
4
 
#  Copyright (C) 2001-2003 Philippe Troin <phil@fifi.org>
5
 
#  Copyright (C) 1996-98 by Dominik Kubla, <kubla@Uni-Mainz.DE> and
6
 
#                        Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
7
 
#
8
 
 
9
 
### BEGIN INIT INFO
10
 
# Provides:          am-utils
11
 
# Required-Start:    $portmap $remote_fs $syslog
12
 
# Required-Stop:     $portmap $remote_fs $syslog
13
 
# Should-Start:      ypbind nslcd
14
 
# Should-Stop:       ypbind nslcd
15
 
# Default-Start:     2 3 4 5
16
 
# Default-Stop:      0 1 6
17
 
# Short-Description: BSD automounter
18
 
# Description:       Automount local and remote filesystems
19
 
### END INIT INFO
20
 
 
21
 
PATH=/usr/sbin:/sbin:/usr/bin:/bin
22
 
export PATH
23
 
 
24
 
# Defaults
25
 
CONF=/etc/default/am-utils
26
 
 
27
 
# If the package is removed, skip it.
28
 
test -x /usr/sbin/amd || exit 0
29
 
 
30
 
get_amd_args() {
31
 
    if [ ! -f "$CONF" ]
32
 
    then
33
 
        echo "$0: not configured yet (try running \"dpkg-reconfigure am-utils\")." 1>&2
34
 
        exit 1
35
 
    fi
36
 
    . "$CONF"
37
 
 
38
 
    if test "$AM_UTILS_USE_NIS" = true
39
 
    then
40
 
        map="$AM_UTILS_NIS_MASTER_MAP"
41
 
        case "$AM_UTILS_NIS_MASTER_MAP_KEY_STYLE" in
42
 
            config)
43
 
                key="$AM_UTILS_NIS_KEY"
44
 
                AMDARGS="`ypmatch \"$key\" \"$map\"`"
45
 
                ;;
46
 
            onekey)
47
 
                AMDARGS="`ypcat \"$map\"`"
48
 
                ;;
49
 
            mountpoint)
50
 
                AMDARGS="`ypcat -k \"$map\"`"
51
 
                ;;
52
 
            custom)
53
 
                AMDARGS="`sh -c \"$AM_UTILS_NIS_CUSTOM\"`"
54
 
                ;;
55
 
            *)
56
 
                echo "$0: bad key style"
57
 
                exit 1
58
 
                ;;
59
 
        esac
60
 
        if [ -z "$AMDARGS" ]
61
 
        then
62
 
            echo "$0: cannot find master map" 1>&2
63
 
            exit 1
64
 
        fi
65
 
    else
66
 
        AMDARGS=""
67
 
 
68
 
        if [ "$AM_UTILS_MAP_NET" = true ]
69
 
        then
70
 
            AMDARGS="$AMDARGS /net /usr/share/am-utils/amd.net"
71
 
        fi
72
 
 
73
 
        if [ "$AM_UTILS_MAP_HOME" = true ]
74
 
        then
75
 
            AMDARGS="$AMDARGS /home /etc/passwd"
76
 
        fi
77
 
 
78
 
        AMDARGS="$AMDARGS $AM_UTILS_MAP_OTHERS"
79
 
    fi
80
 
 
81
 
    if  [ "$AM_UTILS_CLUSTERNAME" != "" ]; then
82
 
        AMDARGS="-C \"$AM_UTILS_CLUSTERNAME\" $AMDARGS"
83
 
    fi
84
 
 
85
 
}
86
 
 
87
 
start_amd() {
88
 
    pid="`amq -p 2>/dev/null`"
89
 
    if [ -n "$pid" ]; then
90
 
        echo "Starting automounter: amd is already running" 1>&2
91
 
        exit 0
92
 
    fi
93
 
 
94
 
    # If the hostname is not a FQHN, add the -d command line switch,
95
 
    # so that hostnames in the maps are stripped correctly.
96
 
    case `hostname` in
97
 
        *.*)    dnsdomain=''
98
 
                ;;
99
 
        *)      if test "$AM_UTILS_USE_NIS" = true; then
100
 
                  dnsdomainname=`dnsdomainname`
101
 
                  if [ "$dnsdomainname" ] ; then
102
 
                    dnsdomain="-d $dnsdomainname"
103
 
                  else
104
 
                    echo "$0: please setup your domainname" 1>&2
105
 
                    exit 1
106
 
                  fi
107
 
                else
108
 
                  dnsdomain=''
109
 
                fi
110
 
                ;;
111
 
    esac
112
 
 
113
 
    get_amd_args
114
 
 
115
 
    echo -n "Starting automounter: amd"
116
 
    /usr/sbin/amd -F /etc/am-utils/amd.conf $dnsdomain $AMDARGS
117
 
    echo "."
118
 
}
119
 
 
120
 
raze_amd() {
121
 
  # This function tries to kill an amd which hasn't exited nicely.
122
 
  # This happens really easily, especially if using mount_type autofs
123
 
 
124
 
  # Get the currently mounted filesystems
125
 
  filesystems=`/bin/tempfile -s .amd`
126
 
  if [ $? -ne 0 ]; then
127
 
    return 1
128
 
  fi
129
 
 
130
 
  amq | awk '$2 !~ "root" {print $1}' > $filesystems
131
 
 
132
 
  # Kill the daemon
133
 
  kill -9 "$pid"
134
 
 
135
 
  sleep 10
136
 
 
137
 
  if kill -s 0 $pid; then
138
 
    rm -f $filesystems
139
 
    return 1
140
 
  fi
141
 
 
142
 
  # Attempt to forcibly unmount the remaining filesystems
143
 
  returncode=0
144
 
  tac $filesystems | while read fs; do
145
 
    umount -l -f "$fs" || returncode=1
146
 
    sleep 1
147
 
  done
148
 
 
149
 
  rm -f $filesystems
150
 
  return $returncode
151
 
}
152
 
 
153
 
stop_amd() {
154
 
    pid="`amq -p 2>/dev/null`"
155
 
    if [ -z "$pid" ]; then
156
 
        echo "Stopping automounter: amd not running" 1>&2
157
 
        if [ $# -eq 0 ]
158
 
        then
159
 
            exit 0
160
 
        else
161
 
            return
162
 
        fi
163
 
    fi
164
 
    echo -n "Requesting amd unmount filesystems: "
165
 
    amq | awk '{print $1}' | tac | xargs -r -n 1 amq -u
166
 
    echo " done."
167
 
    echo -n "Stopping automounter: amd "
168
 
    kill -s TERM "$pid"
169
 
    # wait until amd has finished; this may take a little bit, and amd can't
170
 
    # start while an old one is running
171
 
    i=0
172
 
    maxsecs=120
173
 
    while [ $i -le $maxsecs ] && kill -s 0 $pid >/dev/null 2>&1; do
174
 
        echo -n "."
175
 
        sleep 1
176
 
        i="`expr $i + 1`"
177
 
        [ $i -eq 15 ] && echo -n " [will wait `expr $maxsecs - $i` secs more] "
178
 
    done
179
 
    if kill -s 0 $pid >/dev/null 2>&1
180
 
    then
181
 
        if raze_amd; then
182
 
          echo " done."
183
 
        else
184
 
          echo " failed."
185
 
          exit 1
186
 
        fi
187
 
    else
188
 
        echo " done."
189
 
    fi
190
 
}
191
 
 
192
 
case "$1" in
193
 
  start)
194
 
        start_amd
195
 
        ;;
196
 
 
197
 
  stop)
198
 
        stop_amd
199
 
        ;;
200
 
 
201
 
 
202
 
  restart|force-reload)
203
 
        stop_amd -noquit
204
 
        start_amd
205
 
        ;;
206
 
 
207
 
  reload)
208
 
        # amd tests itself if its map files have changed, so nothing to do here
209
 
        ;;
210
 
 
211
 
  *)
212
 
        echo "Usage: /etc/init.d/amd {start|stop|restart|[force-]reload}"
213
 
        exit 1
214
 
esac
215
 
 
216
 
exit 0