File: openafs-client.init

package info (click to toggle)
openafs 1.8.14-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 42,972 kB
  • sloc: ansic: 455,934; xml: 66,858; perl: 11,967; makefile: 10,038; sh: 7,955; objc: 6,354; java: 5,638; cpp: 2,268; asm: 1,214; yacc: 441; tcl: 249; lex: 201; csh: 85
file content (264 lines) | stat: -rwxr-xr-x 8,030 bytes parent folder | download | duplicates (2)
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#! /bin/sh
### BEGIN INIT INFO
# Provides:             openafs-client
# Required-Start:       $remote_fs $network $time
# Required-Stop:        $remote_fs $network
# Should-Start:         $syslog $named openafs-fileserver
# Should-Stop:          openafs-fileserver
# X-Stop-After:         autofs
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    OpenAFS client
# Description:          Starts or stops the OpenAFS client, loading the
#                       OpenAFS kernel module as necessary.
### END INIT INFO
#
# Modified by Sam Hartman <hartmans@mit.edu> for Debian
# Copyright 2000, International Business Machines Corporation and others.
# All Rights Reserved.
# 
# This software has been released under the terms of the IBM Public
# License.  For details, see the LICENSE file in the top-level source
# directory or online at http://www.openafs.org/dl/license10.html

# This init script bears little resemblence to the regular upstream init
# script at this point and is therefore maintained as a Debian-specific file.
# The upstream init script assumes Red Hat paths and uses insmod to load the
# module directly rather than using modprobe.

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

CACHEINFO=${CACHEINFO:-/etc/openafs/cacheinfo}
MODULEROOT=${MODULEROOT:-/lib/modules/`uname -r`}
MODULEDIR=${MODULEDIR:-$MODULEROOT/fs}
DKMSDIR=${DKMSDIR:-$MODULEROOT/updates/dkms}

# Exit if the package is not installed.
[ -x /usr/sbin/afsd ] || exit 0

# Define LSB log_* functions and get other support infrastructure.
. /lib/lsb/init-functions

exec 3>/dev/null
exec </dev/null

# Gather up options and post startup script name, if present
if [ -f /etc/openafs/afs.conf ]; then
    . /etc/openafs/afs.conf
fi

# Return 1 if the argument is "true".
is_on() {
    if [ x"$1" = x"true" ] ; then
        return 0
    else
        return 1
    fi
}

# Determine if kernel module loading is disabled.  If it's not, don't attempt
# to stop or restart AFS, since we'll end up in a bad inconsistent state.
is_loading_disabled() {
    disabled=`cat /proc/sys/kernel/modules_disabled 2>/dev/null`
    if [ "$disabled" = 1 ] ; then
        return 0
    else
        return 1
    fi
}

# Load the AFS client module if it's not already loaded.  Set $MODULEDIR and
# $LIBAFS to override the default location and module name.  Also check before
# loading whether the module is listed in the module dependencies so that we
# can exit with a 0 status in that case.
load_client() {
    if [ -z "$LIBAFS" ] ; then
        LIBAFS=openafs.ko
    fi
    if [ ! -f "$MODULEDIR/$LIBAFS" -a ! -f "$DKMSDIR/$LIBAFS" ] ; then
        echo ""
        cat <<EOF >&2
AFS module $MODULEDIR/$LIBAFS does not exist.
Not starting AFS.  Please consider building kernel modules using
instructions in /usr/share/doc/openafs-client/README.modules
EOF
        # We must exit successfully here or openafs-client will fail on
        # installation unless a module is installed.
        exit 0
    fi
    sawdep=0
    if grep -q openafs "$MODULEROOT/modules.dep" ; then
        sawdep=1
    fi
    LOADED=`/sbin/lsmod | fgrep openafs`
    if [ -z "$LOADED" ] ; then
        modprobe openafs
        status=$?
        if [ $status = 0 ] ; then
            echo -n " openafs"
        fi

        # We must exit successfully here if the openafs module just isn't
        # listed in the dependency information for modprobe, which can happen
        # if openafs-client and the module package are installed at the same
        # time and the module hasn't been set up yet.
        if [ $sawdep = 0 ] ; then
            return 0
        else
            return $status
        fi
    fi
    return 0
}

# Determine which afsd options to use.  /etc/openafs/afs.conf contains the
# settings that are checked here.
choose_afsd_options() {
    if [ -z "$OPTIONS" ] || [ "$OPTIONS" = "AUTOMATIC" ] ; then
        AFSD_OPTIONS="$VERBOSE"
    else
        AFSD_OPTIONS="$OPTIONS $VERBOSE"
    fi

    # These variables are from /etc/openafs/afs.conf.client and are managed
    # automatically by debconf.
    if is_on $AFS_AFSDB ; then
        AFSD_OPTIONS="$AFSD_OPTIONS -afsdb"
    fi
    if [ "$AFS_DYNROOT" = 'Yes' ] || [ "$AFS_DYNROOT" = 'true' ] ; then
        AFSD_OPTIONS="$AFSD_OPTIONS -dynroot"
    elif [ "$AFS_DYNROOT" = 'Sparse' ] ; then
        AFSD_OPTIONS="$AFSD_OPTIONS -dynroot-sparse"
    fi
    if is_on $AFS_FAKESTAT ; then
        AFSD_OPTIONS="$AFSD_OPTIONS -fakestat"
    fi
}

# Start afsd.  Be careful not to start it if another one is already running,
# as that has a bad tendency to hang the system.  Earlier versions of the
# openafs-client package put afsd in /sbin.
start_client() {
    if pidof /sbin/afsd >/dev/null || pidof /usr/sbin/afsd >/dev/null ; then
        echo "."
    else
        choose_afsd_options
        echo " afsd."
        start-stop-daemon --start --quiet --exec /usr/sbin/afsd -- $AFSD_OPTIONS
    fi

    # From /etc/openafs/afs.conf.client, whether to enable fcrypt encryption.
    if is_on $AFS_CRYPT ; then
        fs setcrypt on
    fi

    # From /etc/openafs/afs.conf, set a sysname list if one was configured.
    if [ -n "$AFS_SYSNAME" ] ; then
        fs sysname $AFS_SYSNAME
    fi
}

# Kill all processes that are accessing AFS.  Not enabled by default, and
# normally called via kill_all_afs.
kill_afs() {
    signal=$1
    mount=`grep ^'AFS ' /etc/mtab | awk '{ print $2 }'`
    if [ -n "$mount" ] ; then
        pids=`/usr/bin/lsof -Fp $mount | sed 's/p//'`
        if [ -n "$pids" ] ; then
            kill -$signal $pids > /dev/null 2>&1
            sleep 1
        fi
    fi
}

# Repeatedly call kill_afs for a series of signals to give AFS-using processes
# a hope of shutting down cleanly if the system is shutting down.  Not enabled
# by default.  Enable this in /etc/openafs/afs.conf.
#
# Warns and does nothing if lsof is not installed.
kill_all_afs() {
    runlevel=`runlevel | sed 's/^. //'`
    if [ "$runlevel" -eq 0 ] || [ "$runlevel" -eq 6 ] ; then
        if [ -x /usr/bin/lsof ] ; then
            echo -n "Killing processes with AFS files open: "
            kill_afs HUP
            kill_afs TERM
            kill_afs ABRT
            kill_afs KILL
            echo "done."
        else
            echo '/usr/bin/lsof not found, not killing processes' >&2
        fi
    fi
}


case "$1" in 
start)
    if is_on $AFS_CLIENT && test -x /usr/sbin/afsd ; then
        echo -n "Starting AFS services:"
        if load_client ; then
            start_client
            $AFS_POST_INIT
        else
            echo ""
            echo "Failed to load AFS kernel module, not starting AFS" >&2
            exit 1
        fi
    fi
    ;;

force-start)
    if test -x /usr/sbin/afsd ; then
        echo -n "Starting AFS services:"
        if load_client ; then
            start_client
            $AFS_POST_INIT
        else
            echo ""
            echo "Failed to load AFS kernel module, not starting AFS" >&2
            exit 1
        fi
    fi
    ;;

stop|force-stop)
    if is_loading_disabled ; then
        echo "Module loading disabled, cannot stop AFS" >&2
        exit 1
    fi
    $AFS_PRE_SHUTDOWN
    echo -n "Stopping AFS services:"
    if grep -q '^AFS ' /etc/mtab ; then
        umount `grep ^'AFS ' /etc/mtab | awk '{ print $2 }'`
        echo -n " afsd"
    fi
    if pidof /usr/sbin/afsd >/dev/null || pidof /sbin/afsd >/dev/null ; then
         afsd -shutdown
    fi

    # If running with the -rmtsys option, afsd doesn't kill the rmtsys helper
    # on afsd -shutdown.  Run start-stop-daemon to make sure that everything
    # is dead.
    start-stop-daemon --stop --quiet --name afsd

    LIBAFS=`/sbin/lsmod | awk 'BEGIN { FS = " " } /openafs/ { print $1 }'`
    if [ -n "$LIBAFS" ] ; then
        /sbin/rmmod $LIBAFS
        echo -n " openafs"
    fi
    echo "."
    ;;

restart|force-reload)
    "$0" stop
    "$0" start
    ;;

*)
    echo Usage: \
        'openafs-client {start|force-start|stop|restart|force-reload}' >&2
    exit 1

esac