-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfs-client.sh
100 lines (89 loc) · 2.22 KB
/
nfs-client.sh
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
#!/bin/sh
#
# Setup NFS client and mount server.
#
#
. /etc/emulab/paths.sh
OS=$(uname -s)
HOSTNAME=$(hostname -s)
#
# The storage partition is mounted on /nfs, if you change this, you
# must change profile.py also.
#
NFSDIR="/nfs"
#
# The name of the nfs server. If you change these, you have to
# change profile.py also.
#
NFSNETNAME="nfsLan"
NFSSERVER="nfs-$NFSNETNAME"
#
# The name of the "prepare" for image snapshot hook.
#
HOOKNAME="$BINDIR/prepare.pre.d/nfs-client.sh"
if ! (grep -q $NFSSERVER /etc/hosts); then
echo "$NFSSERVER is not in /etc/hosts"
exit 1
fi
#
# On Linux, see if the packages are installed
#
if [ "$OS" = "Linux" ]; then
# === Software dependencies that need to be installed. ===
apt-get update
stat=`dpkg-query -W -f '${DB:Status-Status}\n' nfs-common`
if [ "$stat" = "not-installed" ]; then
echo ""
echo "Installing NFS packages"
apt-get --assume-yes install nfs-common
fi
fi
# Wait until nfs is properly set up.
while ! (rpcinfo -s $NFSSERVER | grep -q nfs); do
echo ""
echo "Waiting for NFS server $NFSSERVER ..."
sleep 2
done
# Create the local mount directory.
if [ ! -e $NFSDIR ]; then
mkdir -p -m 755 $NFSDIR
fi
mntopts=
if [ "$OS" = "Linux" ]; then
mntopts="rw,bg,sync,hard,intr"
else
mntopts="nfsv3,tcp,rw,bg,hard,intr"
fi
#
# Run the mount. It is a background mount, so will keep trying until
# the server is up, which it already should be,
#
echo ""
echo "Mounting $NFSSERVER:$NFSDIR ..."
if ! mount -t nfs -o $mntopts $NFSSERVER:$NFSDIR $NFSDIR; then
echo 'WARNING: Background mount failed?! Trying again in 5 seconds ...'
sleep 5
if ! mount -t nfs -o $mntopts $NFSSERVER:$NFSDIR $NFSDIR; then
echo 'FATAL: Background mount failed?! Giving up.'
exit 1
fi
fi
#
# But do not exit until the mount is made, in case there is another
# script after this one, that depends on the mount really being there.
#
if [ "$OS" = "Linux" ]; then
while ! (findmnt $NFSDIR); do
echo "Waiting for NFS mount of $NFSDIR ..."
sleep 2
done
else
while ! mount | grep -q "^$NFSSERVER:$NFSDIR"; do
echo "Waiting for NFS mount of $NFSDIR ..."
sleep 2
done
fi
mkdir /home/copy #for use in testing
echo ""
echo "Mount of $NFSSERVER:$NFSDIR is ready."
exit 0