Skip to content

Instantly share code, notes, and snippets.

@jacopen
Created January 22, 2013 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacopen/4595273 to your computer and use it in GitHub Desktop.
Save jacopen/4595273 to your computer and use it in GitHub Desktop.
Check read/write to nfs.
require "timeout"
pid = fork do
require "fileutils"
filepath = "/mnt/nfs/test1/test.txt"
begin
File::open(filepath,
File::Constants::WRONLY |
File::Constants::CREAT |
File::Constants::TRUNC |
File::Constants::SYNC, 0644) do |f|
f.write("test")
end
FileUtils.rm(filepath)
exit 0
rescue => e
exit 1
end
end
begin
timeout(10) do
code = Process.wait2[1]
if code == 0
puts "NFS check successful"
exit 0
else
puts "NFS check failed - R/W Error"
exit 1
end
end
rescue Timeout::Error => e
puts "NFS check failed - Timeout Error"
Process.kill('SIGKILL', pid)
puts "Child process terminated - pid: " + pid.to_s
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment