Class: Pwrake::GfarmDirectory
Constant Summary
collapse
- @@prefix =
nil
- @@work_dir =
nil
- @@log_dir =
nil
- @@gfarm2fs_option =
nil
- @@gfarm2fs_debug =
nil
- @@gfarm2fs_debug_wait =
1
- @@current_id =
0
- @@hostname =
Socket.gethostname
Class Method Summary
collapse
Instance Method Summary
collapse
#cd, #close_messages, #current, #log_path, #open_messages, #work_dir, #work_path
Constructor Details
Returns a new instance of GfarmDirectory.
26
27
28
29
30
31
32
|
# File 'lib/pwrake/worker/gfarm_directory.rb', line 26
def initialize
super
@id = @@current_id
@@current_id += 1
@suffix = "%05d_%03d" % [Process.pid,@id]
@gfarm_mountpoint = @@prefix+"_"+@suffix
end
|
Class Method Details
.init(opts) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/pwrake/worker/gfarm_directory.rb', line 15
def self.init(opts)
@@prefix = opts[:base_dir]
@@work_dir = opts[:work_dir]
@@log_dir = opts[:log_dir]
@@gfarm2fs_command = opts[:gfarm2fs_command] || 'gfarm2fs'
@@gfarm2fs_option = opts[:gfarm2fs_option]
@@gfarm2fs_debug = opts[:gfarm2fs_debug]
@@gfarm2fs_debug_wait = opts[:gfarm2fs_debug_wait]
Dir.chdir(ENV['HOME'])
end
|
Instance Method Details
#check_mountpoint ⇒ Object
116
117
118
119
120
121
122
123
|
# File 'lib/pwrake/worker/gfarm_directory.rb', line 116
def check_mountpoint
unless File.directory?(@gfarm_mountpoint)
@log.warn "remounting #{@@hostname}:#{@gfarm_mountpoint}"
close
open
end
end
|
#close ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/pwrake/worker/gfarm_directory.rb', line 76
def close
super
n = 0
while n < 4
begin
if mounted?
sleep 0.15 * 4**n
spawn_cmd "fusermount -u #{@gfarm_mountpoint}"
end
n = 99
rescue => e
@log.error e.message+" n=#{n}"
n += 1
end
end
if File.directory? @gfarm_mountpoint
begin
FileUtils.rmdir @gfarm_mountpoint
@log.info "rmdir #{@@hostname}:#{@gfarm_mountpoint}"
rescue
@log.error "failed to rmdir #{@@hostname}:#{@gfarm_mountpoint}"
end
end
if File.exist? @gfarm_mountpoint
@log.warn "mountpoint #{@@hostname}:#{@gfarm_mountpoint} remains"
end
end
|
#home_path ⇒ Object
34
35
36
|
# File 'lib/pwrake/worker/gfarm_directory.rb', line 34
def home_path
Pathname.new(@gfarm_mountpoint)
end
|
#mounted? ⇒ Boolean
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/pwrake/worker/gfarm_directory.rb', line 104
def mounted?
File.open('/etc/mtab','r') do |f|
f.each_line do |l|
a = l.split
if a[1] == @gfarm_mountpoint && a[2] =~ /gfarm2fs/
return true
end
end
end
false
end
|
#open ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/pwrake/worker/gfarm_directory.rb', line 58
def open
FileUtils.mkdir_p @gfarm_mountpoint
@log.info "mkdir -p #{@@hostname}:#{@gfarm_mountpoint}"
path = @log.path
begin
if @@gfarm2fs_debug && path
f = path+("gfarm2fs-"+@@hostname+"-"+@suffix)
spawn_cmd "#{@@gfarm2fs_command} #{@@gfarm2fs_option} -d #{@gfarm_mountpoint} > #{f} 2>&1 & sleep #{@@gfarm2fs_debug_wait}"
else
spawn_cmd "#{@@gfarm2fs_command} #{@@gfarm2fs_option} #{@gfarm_mountpoint}"
end
rescue => exc
sleep 1
raise exc
end
super
end
|
#spawn_cmd(cmd) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/pwrake/worker/gfarm_directory.rb', line 38
def spawn_cmd(cmd)
@log.info "spawn_cmd: "+cmd
r,w = IO.pipe
pid = spawn(cmd,[:out,:err]=>w)
w.close
pidmy,status = Process.waitpid2(pid)
a = []
while s = r.gets
a << s.chomp
end
if status.success?
msg = a.empty? ? cmd : cmd+" => #{a.join(',')}"
@log.info msg
else
msg = "failed to execute `#{cmd}' => #{a.join(',')}"
raise msg
end
a
end
|