lauv-aux: added storage server script.

This commit is contained in:
Ricardo Martins 2015-03-16 11:10:20 +00:00
parent d5f8a21580
commit 94c685de8f
2 changed files with 136 additions and 0 deletions

View File

@ -2,6 +2,7 @@ cfg_architecture='cortex-a8-hardfp'
cfg_storage='data0:ext4:/opt' cfg_storage='data0:ext4:/opt'
cfg_modules='' cfg_modules=''
cfg_services0='network dropbear storage upgrade syslog ptpd' cfg_services0='network dropbear storage upgrade syslog ptpd'
cfg_services1='lauv-storage-server'
cfg_services2='dune' cfg_services2='dune'
cfg_packages='u-boot dropbear rsync busybox e2fsprogs dosfstools ptpd am33xx-cm3/host rpcbind nfs-utils linux' cfg_packages='u-boot dropbear rsync busybox e2fsprogs dosfstools ptpd am33xx-cm3/host rpcbind nfs-utils linux'
cfg_target_linux_kernel='arch/arm/boot/zImage' cfg_target_linux_kernel='arch/arm/boot/zImage'
@ -9,6 +10,7 @@ cfg_target_linux_dtb='arch/arm/boot/dts/am335x-lauv-aux.dtb'
cfg_target_uboot_config='am335x_bbb' cfg_target_uboot_config='am335x_bbb'
cfg_ptpd_interface='eth0' cfg_ptpd_interface='eth0'
cfg_terminal='ttyO0' cfg_terminal='ttyO0'
cfg_lauv_storage_dir='/opt/lsts/dune/log'
cfg_partitions=\ cfg_partitions=\
( (
x-boot boot0 512B 32MiB x-boot boot0 512B 32MiB

View File

@ -0,0 +1,134 @@
mount_storage()
{
echo "* Probing storage..."
dev="$(ls $1 2> /dev/null)"
if [ -z "$dev" ]; then
echo "* Storage not present."
return 1
fi
bdev="/dev/${dev}$2"
if ! [ -b "$bdev" ]; then
echo "* Device $bdev does not exist."
return 1
fi
mkdir -p "$cfg_lauv_storage_dir"
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" "$2"
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 \
-o rw,sync,no_root_squash,no_subtree_check \
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..."
exportfs -au
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()
{
# Removable storage.
try_mount_storage \
/sys/devices/ocp.3/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb2/2-1/2-1:1.0/host0/target0:0:0/0:0:0:0/block \
1
# Internal storage.
if [ $? -ne 0 ]; then
try_mount_storage \
/sys/devices/ocp.3/48060000.mmc/mmc_host/mmc?/mmc?:*/block \
p1
fi
# FIXME: what to do if the above fails.
start_nfs_server
}
stop()
{
stop_nfs_server
echo "* Unmounting storage.."
umount "$cfg_lauv_storage_dir"
}