Class: Pwrake::GfarmDirectory

Inherits:
SharedDirectory show all
Defined in:
lib/pwrake/worker/gfarm_directory.rb

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

Methods inherited from SharedDirectory

#cd, #close_messages, #current, #log_path, #open_messages, #work_dir, #work_path

Constructor Details

#initializeGfarmDirectory

Returns a new instance of GfarmDirectory.



25
26
27
28
29
30
31
# File 'lib/pwrake/worker/gfarm_directory.rb', line 25

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
# 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_option = opts[:gfarm2fs_option]
  @@gfarm2fs_debug = opts[:gfarm2fs_debug]
  @@gfarm2fs_debug_wait = opts[:gfarm2fs_debug_wait]
  Dir.chdir(ENV['HOME'])
end

Instance Method Details

#closeObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pwrake/worker/gfarm_directory.rb', line 74

def close
  super
  if File.directory? @gfarm_mountpoint
    begin
      spawn_cmd "fusermount -u #{@gfarm_mountpoint}"
    rescue
    end
    #system "sync"
    begin
      FileUtils.rmdir @gfarm_mountpoint
      @log.info "rmdir #{@gfarm_mountpoint} @#{@@hostname}"
    rescue
      @log.error "failed to rmdir #{@gfarm_mountpoint} @#{@@hostname}"
    end
  end
end

#home_pathObject



33
34
35
# File 'lib/pwrake/worker/gfarm_directory.rb', line 33

def home_path
  Pathname.new(@gfarm_mountpoint)
end

#openObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pwrake/worker/gfarm_directory.rb', line 57

def open
  FileUtils.mkdir_p @gfarm_mountpoint
  path = @log.path
  begin
    if @@gfarm2fs_debug && path
      f = path+("gfarm2fs-"+@@hostname+"-"+@suffix)
      spawn_cmd "gfarm2fs #{@@gfarm2fs_option} -d #{@gfarm_mountpoint} > #{f} 2>&1 & sleep #{@@gfarm2fs_debug_wait}"
    else
      spawn_cmd "gfarm2fs #{@@gfarm2fs_option} #{@gfarm_mountpoint}"
    end
  rescue => exc
    sleep 1
    raise exc
  end
  super
end

#spawn_cmd(cmd) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pwrake/worker/gfarm_directory.rb', line 37

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