views:

219

answers:

1

How can I check if an NFS share on network is online/available/alive using Ruby code (on Linux)?

I have a code like this at the moment:

while !Ping.pingecho('192.168.1.116')
end
`mount -a`
exec 'SOMETHING THAT IS PLACED ON NFS SHARE'

And it doesn't work quite OK, because the remote machine exporting the share don't always have the NFS service ready as soon as it goes online on network. That is; it responds to pings but; I'm unable to mount it unless the NFS service starts.

+1  A: 

Run the command

rpcinfo -u 192.168.1.116 nfs 3

and check the return status. This invokes NFS procedure 0 on 192.168.1.116, which essentially is an RPC ping. You should redirect stdout and stderr somewhere, as this command apparently has no quiet mode.

Martin v. Löwis
I hate to say this but; rpcinfo command is not supported on the platform I'm working with...
kramer
if you bypass the portmapper (which you can, since NFS uses fixed ports, anyway), writing this rpcinfo call in pure ruby shouldn't be too difficult. It's just a single, fixed UDP packet which you can sniff and hard-code, and you just have to look at a few bits of the reply if you get any. Assuming the NFS server supports TCP, just creating a TCP connection may be sufficient.
Martin v. Löwis