]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/nfs-utils/files/nfsserver
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / nfs-utils / files / nfsserver
1 #!/bin/sh
2 #
3 # Startup script for nfs-utils
4 #
5 # The nfsd kernel module must exist along with its dependencies
6 modprobe -n nfsd || exit 0
7 #
8 # The environment variable NFS_SERVERS may be set in /etc/default/nfsd
9 # Other control variables may be overridden here too
10 test -r /etc/default/nfsd && . /etc/default/nfsd
11 #
12 # Location of exectuables:
13 test -x "$NFS_MOUNTD" || NFS_MOUNTD=/usr/sbin/mountd
14 test -x "$NFS_NFSD" || NFS_NFSD=/usr/sbin/nfsd
15 #
16 # The user mode program must also exist (it just starts the kernel
17 # threads using the kernel module code).
18 test -x "$NFS_MOUNTD" || exit 0
19 test -x "$NFS_NFSD" || exit 0
20 #
21 # Default is 8 threads, value is settable between 1 and the truely
22 # ridiculous 99
23 test "$NFS_SERVERS" -gt 0 && "$NFS_SERVERS" -lt 100 || NFS_SERVERS=8
24 #
25 # The default state directory is /var/lib/nfs
26 test -n "$NFS_STATEDIR" || NFS_STATEDIR=/var/lib/nfs
27 #
28 #----------------------------------------------------------------------
29 # Startup and shutdown functions.
30 #  Actual startup/shutdown is at the end of this file.
31 #directories
32 create_directories(){
33         echo -n 'creating NFS state directory: '
34         mkdir -p "$NFS_STATEDIR"
35         (       cd "$NFS_STATEDIR"
36                 umask 077
37                 mkdir -p sm sm.bak
38                 test -w sm/state || {
39                         rm -f sm/state
40                         :>sm/state
41                 }
42                 umask 022
43                 for file in xtab etab smtab rmtab
44                 do
45                         test -w "$file" || {
46                                 rm -f "$file"
47                                 :>"$file"
48                         }
49                 done
50         )
51         echo done
52 }
53 #mountd
54 start_mountd(){
55         echo -n 'starting mountd: '
56         start-stop-daemon --start --exec "$NFS_MOUNTD" -- "$@"
57         echo done
58 }
59 stop_mountd(){
60         echo -n 'stopping mountd: '
61         start-stop-daemon --stop --quiet --exec "$NFS_MOUNTD"
62         echo done
63 }
64 #
65 #nfsd
66 start_nfsd(){
67         echo -n "starting $1 nfsd kernel threads: "
68         start-stop-daemon --start --exec "$NFS_NFSD" -- "$@"
69         echo done
70 }
71 delay_nfsd(){
72         for delay in 0 1 2 3 4 5 6 7 8 9 
73         do
74                 if pidof nfsd >/dev/null
75                 then
76                         echo -n .
77                         sleep 1
78                 else
79                         return 0
80                 fi
81         done
82         return 1
83 }
84 stop_nfsd(){
85         # WARNING: this kills any process with the executable
86         # name 'nfsd'.
87         echo -n 'stopping nfsd: '
88         start-stop-daemon --stop --quiet --signal 1 --name nfsd
89         if delay_nfsd || {
90                 echo failed
91                 echo ' using signal 9: '
92                 start-stop-daemon --stop --quiet --signal 9 --name nfsd
93                 delay_nfsd
94         }
95         then
96                 echo done
97                 # This will remove, recursively, dependencies
98                 echo -n 'removing nfsd kernel module: '
99                 if modprobe -r nfsd
100                 then
101                         echo done
102                 else
103                         echo failed
104                 fi
105         else
106                 echo failed
107         fi
108 }
109 #----------------------------------------------------------------------
110 #
111 # supported options:
112 #  start
113 #  stop
114 #  reload: reloads the exports file
115 #  restart: stops and starts mountd
116 #FIXME: need to create the /var/lib/nfs/... directories
117 case "$1" in
118 start)  create_directories
119         start_nfsd "$NFS_SERVERS"
120         start_mountd
121         test -r /etc/exports && exportfs -a;;
122 stop)   exportfs -ua
123         stop_mountd
124         stop_nfsd;;
125 reload) test -r /etc/exports && exportfs -r;;
126 restart)exportfs -ua
127         stop_mountd
128         # restart does not restart the kernel threads,
129         # only the user mode processes
130         start_mountd
131         test -r /etc/exports && exportfs -a;;
132 esac