~ubuntu-branches/ubuntu/lucid/nfs-utils/lucid

« back to all changes in this revision

Viewing changes to debian/nfs-kernel-server.init

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2006-07-03 10:36:59 UTC
  • mto: (12.1.1 feisty)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20060703103659-71qzs6f21zzmjmhx
Tags: upstream-1.0.8
ImportĀ upstreamĀ versionĀ 1.0.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
#
3
 
# nfs-kernel-server
4
 
#               This shell script takes care of starting and stopping
5
 
#               the kernel-mode NFS server.
6
 
#
7
 
# chkconfig: 345 60 20
8
 
# description: NFS is a popular protocol for file sharing across TCP/IP \
9
 
#              networks. This service provides NFS server functionality, \
10
 
#              which is configured via the /etc/exports file.
11
 
#
12
 
 
13
 
set -e
14
 
 
15
 
# What is this?
16
 
DESC="NFS kernel daemon"
17
 
PREFIX=/usr
18
 
 
19
 
# Exit if required binaries are missing.
20
 
[ -x $PREFIX/sbin/rpc.nfsd    ] || exit 0
21
 
[ -x $PREFIX/sbin/rpc.mountd  ] || exit 0
22
 
[ -x $PREFIX/sbin/exportfs    ] || exit 0
23
 
[ -x $PREFIX/sbin/rpc.svcgssd ] || exit 0
24
 
 
25
 
# Read config
26
 
DEFAULTFILE=/etc/default/nfs-kernel-server
27
 
RPCNFSDCOUNT=8
28
 
RPCMOUNTDOPTS=
29
 
NEED_SVCGSSD=yes
30
 
RPCGSSDOPTS=
31
 
RPCSVCGSSDOPTS=
32
 
PROCNFSD_MOUNTPOINT=/proc/fs/nfsd
33
 
if [ -f $DEFAULTFILE ]; then
34
 
    . $DEFAULTFILE
35
 
fi
36
 
 
37
 
do_modprobe() {
38
 
    modprobe -q "$1" || true
39
 
}
40
 
 
41
 
do_mount() {
42
 
    if ! grep -E -qs "$1\$" /proc/filesystems
43
 
    then
44
 
        return 1
45
 
    fi
46
 
    if ! mountpoint -q "$2"
47
 
    then
48
 
        mount -t "$1" "$1" "$2"
49
 
        return
50
 
    fi
51
 
    return 0
52
 
}
53
 
 
54
 
# See how we were called.
55
 
case "$1" in
56
 
  start)
57
 
        cd /    # daemons should have root dir as cwd
58
 
        if grep -q '^/' /etc/exports
59
 
        then
60
 
                do_modprobe nfsd
61
 
                do_mount nfsd $PROCNFSD_MOUNTPOINT || NEED_SVCGSSD=no
62
 
                printf "Exporting directories for $DESC..."
63
 
                $PREFIX/sbin/exportfs -r
64
 
                echo "done."
65
 
 
66
 
                printf "Starting $DESC:"
67
 
                if [ "$NEED_SVCGSSD" = yes ]
68
 
                then
69
 
                    printf " svcgssd"
70
 
                    start-stop-daemon --start --quiet \
71
 
                            --make-pidfile --pidfile /var/run/rpc.svcgssd.pid \
72
 
                            --exec $PREFIX/sbin/rpc.svcgssd -- $RPCSVCGSSDOPTS
73
 
                fi
74
 
 
75
 
                printf " nfsd"
76
 
                start-stop-daemon --start --quiet \
77
 
                    --exec $PREFIX/sbin/rpc.nfsd -- $RPCNFSDCOUNT
78
 
 
79
 
                printf " mountd"
80
 
 
81
 
                # make sure 127.0.0.1 is a valid source for requests
82
 
                ClearAddr=
83
 
                if [ -f /proc/net/rpc/auth.unix.ip/channel ]
84
 
                then
85
 
                    fgrep -qs 127.0.0.1 /proc/net/rpc/auth.unix.ip/content || {
86
 
                        echo "nfsd 127.0.0.1 2147483647 localhost" >/proc/net/rpc/auth.unix.ip/channel
87
 
                        ClearAddr=yes
88
 
                    }
89
 
                fi
90
 
 
91
 
                $PREFIX/bin/rpcinfo -u localhost nfs 3 >/dev/null 2>&1 ||
92
 
                    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3"
93
 
 
94
 
                [ -z "$ClearAddr" ] || echo "nfsd 127.0.0.1 1" >/proc/net/rpc/auth.unix.ip/channel
95
 
 
96
 
                start-stop-daemon --start --quiet \
97
 
                    --exec $PREFIX/sbin/rpc.mountd -- $RPCMOUNTDOPTS
98
 
                echo "."
99
 
        else
100
 
                echo "Not starting $DESC: No exports."
101
 
        fi
102
 
        ;;
103
 
 
104
 
  stop)
105
 
        printf "Stopping $DESC: mountd"
106
 
        start-stop-daemon --stop --oknodo --quiet \
107
 
            --name rpc.mountd --user 0
108
 
        if [ "$NEED_SVCGSSD" = yes ]
109
 
        then
110
 
            printf " svcgssd"
111
 
            start-stop-daemon --stop --oknodo --quiet \
112
 
                    --name rpc.svcgssd --user 0
113
 
            rm -f /var/run/rpc.svcgssd.pid
114
 
        fi
115
 
        printf " nfsd"
116
 
        start-stop-daemon --stop --oknodo --quiet \
117
 
            --name nfsd --user 0 --signal 2
118
 
        echo "."
119
 
 
120
 
        printf "Unexporting directories for $DESC..."
121
 
        $PREFIX/sbin/exportfs -au
122
 
        echo "done."
123
 
        ;;
124
 
 
125
 
  reload | force-reload)
126
 
        printf "Re-exporting directories for $DESC..."
127
 
        $PREFIX/sbin/exportfs -r
128
 
        echo "done."
129
 
        ;;
130
 
 
131
 
  restart)
132
 
        $0 stop
133
 
        sleep 1
134
 
        $0 start
135
 
        ;;
136
 
 
137
 
  *)
138
 
        echo "Usage: nfs-kernel-server {start|stop|reload|force-reload|restart}"
139
 
        exit 1
140
 
        ;;
141
 
esac
142
 
 
143
 
exit 0