Module: PleaseRun::Installer
- Defined in:
- lib/pleaserun/installer.rb
Overview
Some helpful methods for installing a runner.
Class Method Summary collapse
- .install(runner) ⇒ Object
- .install_actions(runner) ⇒ Object
-
.install_files(runner, root = "/", overwrite = false) ⇒ Object
Install files provided by a runner.
- .logger ⇒ Object
- .write(fullpath, content, perms) ⇒ Object
- .write_actions(runner, path) ⇒ Object
Class Method Details
.install(runner) ⇒ Object
8 9 10 11 |
# File 'lib/pleaserun/installer.rb', line 8 def install(runner) install_files(runner) install_actions(runner) end |
.install_actions(runner) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# 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) ⇒ Object
Install files provided by a runner.
If overwrite is false and any file already exists, then this method will fail.
16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 ⇒ Object
61 62 63 |
# File 'lib/pleaserun/installer.rb', line 61 def logger return @logger ||= Cabin::Channel.get end |
.write(fullpath, content, perms) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# 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) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# 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 |