module PleaseRun::Installer

Some helpful methods for installing a runner.

Public Instance Methods

install(runner) click to toggle source
# File lib/pleaserun/installer.rb, line 8
def install(runner)
  install_files(runner)
  install_actions(runner)
end
install_actions(runner) click to toggle source
# File lib/pleaserun/installer.rb, line 41
def install_actions(runner)
  return if runner.install_actions.empty?
  # TODO(sissel): Refactor this to be less lines of code or put into methods.
  runner.install_actions.each do |action|
    logger.info("Running install action", :action => action)
    system(action)
    logger.warn("Install action failed", :action => action, :code => $CHILD_STATUS.exitstatus) unless $CHILD_STATUS.success?
  end # each install action
end
install_files(runner, root = "/", overwrite = false) click to toggle source

Install files provided by a runner.

If overwrite is false and any file already exists, then this method will fail.

# File lib/pleaserun/installer.rb, line 16
def install_files(runner, root = "/", overwrite = false)
  errors = 0
  runner.files.each do |path, content, perms|
    # TODO(sissel): Force-set default file permissions if not provided?
    # perms ||= (0666 ^ File.umask)
    fullpath = File.join(root, path)
    raise PleaseRun::FileWritingFailure, "File already exists: #{fullpath}" if !overwrite && File.file?(fullpath)
    success = write(fullpath, content, perms)
    errors += 1 unless success
  end
  raise PleaseRun::FileWritingFailure, "Errors occurred while writing files" if errors > 0
end
logger() click to toggle source
# File lib/pleaserun/installer.rb, line 61
def logger
  return @logger ||= Cabin::Channel.get
end
write(fullpath, content, perms) click to toggle source
# File lib/pleaserun/installer.rb, line 29
def write(fullpath, content, perms)
  logger.log("Writing file", :destination => fullpath)
  FileUtils.mkdir_p(File.dirname(fullpath))
  File.write(fullpath, content)
  logger.debug("Setting permissions", :destination => fullpath, :perms => perms)
  File.chmod(perms, fullpath) if perms
  return true
rescue Errno::EACCES
  logger.error("Access denied in writing a file. Maybe we need to be root?", :path => fullpath)
  return false
end
write_actions(runner, path) click to toggle source
# File lib/pleaserun/installer.rb, line 51
def write_actions(runner, path)
  return if runner.install_actions.empty?
  logger.log("Writing install actions. You will want to run this script to properly activate your service on the target host", :path => path)
  File.open(path, "w") do |fd|
    runner.install_actions.each do |action|
      fd.puts(action)
    end
  end
end