class Hookit::Resource::Mount

Public Class Methods

new(name) click to toggle source
Calls superclass method Hookit::Resource::Base::new
# File lib/hookit/resource/mount.rb, line 17
def initialize(name)
  mount_point(name) unless mount_point
  pass('-') unless pass
  super
end

Public Instance Methods

run(action) click to toggle source
# File lib/hookit/resource/mount.rb, line 23
def run(action)
  case action
  when :mount
    mount!
  when :umount
    umount!
  when :remount
    umount!
    mount!
  when :enable
    disable!
    enable!
  when :disable
    disable!
  end
end

Protected Instance Methods

disable!() click to toggle source
# File lib/hookit/resource/mount.rb, line 66
def disable!
  case platform.os
  when 'sun'
    `egrep -v "#{device}.*#{mount_point}" /etc/vfstab > /tmp/vfstab.tmp; mv -f /tmp/vfstab.tmp /etc/vfstab`
  when 'linux'
    `egrep -v "#{device}.*#{mount_point}" /etc/fstab > /tmp/vfstab.tmp; mv -f /tmp/vfstab.tmp /etc/vfstab`
  end
end
enable!() click to toggle source
# File lib/hookit/resource/mount.rb, line 56
def enable!
  entry = "#{device}\t#{device =~ /^\/dev/ ? device : "-"}\t#{mount_point}\t#{fstype}\t#{pass}\tyes\t#{options!}"
  case platform.os
  when 'sun'
    `echo "#{entry}" >> /etc/vfstab`
  when 'linux'
    `echo "#{entry}" >> /etc/fstab`
  end
end
mount!() click to toggle source
# File lib/hookit/resource/mount.rb, line 42
def mount!
  ::FileUtils.mkdir_p(mount_point)
  case platform.os
  when 'sun'
    run_command! "mount -O -F #{fstype} -o retry=5,timeo=300 #{options!(as_arg=true)} #{device} #{mount_point}"
  when 'linux'
    run_command! "mount -t #{fstype} -o retry=5,timeo=300 #{options!(as_arg=true)} #{device} #{mount_point}"
  end
end
options!(as_arg=false) click to toggle source
# File lib/hookit/resource/mount.rb, line 75
def options!(as_arg=false)
  options = self.options.kind_of?(Array) ? self.options.join(',') : self.options
  if as_arg
    options ? (return "-o #{options}") : (return "")
  end
  options != "" ? (return "#{options}") : (return "-")
end
run_command!(cmd, expect_code=0) click to toggle source
# File lib/hookit/resource/mount.rb, line 83
def run_command!(cmd, expect_code=0)
  `#{cmd}`
  code = $?.exitstatus
  if code != expect_code
    raise Hookit::Error::UnexpectedExit, "#{cmd} failed with exit code '#{code}'"
  end
end
umount!() click to toggle source
# File lib/hookit/resource/mount.rb, line 52
def umount!
  run_command! "umount #{mount_point}"
end