Created
January 22, 2013 15:01
-
-
Save jacopen/4595273 to your computer and use it in GitHub Desktop.
Check read/write to nfs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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