2015-06-03 16:45:47 +01:00
|
|
|
mount_storage()
|
|
|
|
{
|
|
|
|
echo "* Probing storage..."
|
|
|
|
|
2015-12-18 10:51:00 +00:00
|
|
|
bdev="$1"
|
2015-06-03 16:45:47 +01:00
|
|
|
if ! [ -b "$bdev" ]; then
|
|
|
|
echo "* Device $bdev does not exist."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
mount -o rw,relatime "$bdev" "$cfg_lauv_storage_dir" 2> /dev/null
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "* Failed to mount $bdev on $cfg_lauv_storage_dir"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "* Mounted '$bdev' on '$cfg_lauv_storage_dir'"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
try_mount_storage()
|
|
|
|
{
|
|
|
|
n=0; while [ $n -lt 30 ]; do
|
|
|
|
mount_storage "$1"
|
|
|
|
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
let n++
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
start_nfs_server()
|
|
|
|
{
|
|
|
|
echo "* Creating NFS administrative folder..."
|
|
|
|
mkdir -p /var/lib/nfs
|
|
|
|
if ! [ -d /var/lib/nfs ]; then
|
|
|
|
echo "ERROR: failed to create data folder."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "* Launching rpcbind..."
|
|
|
|
/usr/bin/rpcbind
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: failed to start rpcbind."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "* Launching rpc.statd..."
|
|
|
|
/usr/bin/rpc.statd
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: failed to start rpc.statd."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "* Launching rpc.nfsd..."
|
|
|
|
/usr/bin/rpc.nfsd
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: failed to start rpc.nfsd."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "* Creating NFS filesystem table..."
|
|
|
|
/usr/bin/exportfs -ra
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: failed to create filesystem table."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "* Launching rpc.mountd..."
|
|
|
|
/usr/bin/rpc.mountd
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: failed to start rpc.mountd."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "* Exporting NFS filesystems..."
|
|
|
|
/usr/bin/exportfs \
|
2015-06-29 17:23:55 +01:00
|
|
|
-o rw,async,no_root_squash,no_subtree_check \
|
2015-06-03 16:45:47 +01:00
|
|
|
10.0.0.0/16:"$cfg_lauv_storage_dir"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: failed to export filesystems."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
stop_nfs_server()
|
|
|
|
{
|
|
|
|
echo "* Unexporting NFS filesystems..."
|
2016-01-28 11:52:21 +00:00
|
|
|
exportfs -au 2> /dev/null
|
2015-06-03 16:45:47 +01:00
|
|
|
echo "* Terminating rpc.mountd..."
|
|
|
|
killall rpc.mountd 2> /dev/null
|
|
|
|
echo "* Terminating rpc.statd..."
|
|
|
|
killall rpc.statd 2> /dev/null
|
|
|
|
echo "* Terminating rpc.bind..."
|
|
|
|
killall rpcbind 2> /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
start()
|
|
|
|
{
|
2015-12-18 10:51:00 +00:00
|
|
|
mkdir -p "$cfg_lauv_storage_dir"
|
|
|
|
|
2015-06-03 16:45:47 +01:00
|
|
|
# Removable storage.
|
2015-12-18 10:51:00 +00:00
|
|
|
if [ "$cfg_lauv_storage" != "internal" ]; then
|
|
|
|
try_mount_storage /dev/sda1
|
|
|
|
fi
|
2015-06-03 16:45:47 +01:00
|
|
|
|
|
|
|
# FIXME: what to do if the above fails.
|
|
|
|
start_nfs_server
|
|
|
|
}
|
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
|
|
|
stop_nfs_server
|
2015-12-18 10:54:05 +00:00
|
|
|
|
|
|
|
if [ "$cfg_lauv_storage" != "internal" ]; then
|
|
|
|
echo "* Unmounting storage..."
|
|
|
|
umount "$cfg_lauv_storage_dir"
|
|
|
|
fi
|
2015-06-03 16:45:47 +01:00
|
|
|
}
|