class PleaseRun::Platform::Base

Base class for all platforms.

This class provides all the general attributes common among all process runners.

For example, pretty much every runner (upstart, runit, sysv, etc) has concepts for the 'name' of a thing, what program it runs, what user to run as, etc.

Public Class Methods

new(target_version) click to toggle source
# File lib/pleaserun/platform/base.rb, line 166
def initialize(target_version)
  configurable_setup
  self.target_version = target_version
end

Public Instance Methods

all_environment_variables() click to toggle source
# File lib/pleaserun/platform/base.rb, line 242
def all_environment_variables
  parsed_env_vars = {}
  parsed_env_vars = parsed_environment_variables unless parsed_environment_variables.nil?
  flag_env_vars = {}
  flag_env_vars = environment_variables unless environment_variables.nil?

  variables = parsed_env_vars.merge(flag_env_vars)
  return nil if variables.empty?
  result = []
  variables.each {|k, v| result << {'key' => k, 'value' => v} }
  result
end
default_file() click to toggle source
# File lib/pleaserun/platform/base.rb, line 255
def default_file
  "/etc/default/#{name}"
end
install_actions() click to toggle source

The default install_actions is none.

Subclasses which need installation actions should implement this method. This method will return an Array of String commands to execute in order to install this given runner.

For examples, see launchd and systemd platforms.

# File lib/pleaserun/platform/base.rb, line 216
def install_actions
  return []
end
log_path() click to toggle source
# File lib/pleaserun/platform/base.rb, line 220
def log_path
  File.join(log_directory.chomp("/"), name)
end
log_path_stderr() click to toggle source
# File lib/pleaserun/platform/base.rb, line 224
def log_path_stderr
  filename = "#{name}-stderr.log"
  filename = log_file_stderr unless log_file_stderr.nil?
  File.join(log_directory.chomp("/"), filename)
end
log_path_stdout() click to toggle source
# File lib/pleaserun/platform/base.rb, line 230
def log_path_stdout
  filename = "#{name}-stdout.log"
  filename = log_file_stdout unless log_file_stdout.nil?
  File.join(log_directory.chomp("/"), filename)
end
parsed_environment_variables() click to toggle source
# File lib/pleaserun/platform/base.rb, line 236
def parsed_environment_variables
  return {} if environment_file.nil?
  return {} unless File.exist?(environment_file)
  Dotenv::Parser.call(File.open(environment_file, "rb:bom|utf-8", &:read))
end
platform() click to toggle source

Get the platform name for this class. The platform name is simply the lowercased class name, but this can be overridden by subclasses (but don't, because that makes things confusing!)

# File lib/pleaserun/platform/base.rb, line 173
def platform
  self.class.name.split("::").last.gsub(/(?<=[^A-Z])[A-Z]+/, "-\\0").downcase
end
render(text) click to toggle source

Render a text input through Mustache based on this object.

# File lib/pleaserun/platform/base.rb, line 198
def render(text)
  return Mustache.render(text, self)
end
render_template(name) click to toggle source
# File lib/pleaserun/platform/base.rb, line 182
def render_template(name)
  possibilities = [
    File.join(template_path, target_version, name),
    File.join(template_path, "default", name),
    File.join(template_path, name)
  ]

  possibilities.each do |path|
    next unless File.readable?(path) && File.file?(path)
    return render(File.read(path))
  end

  raise InvalidTemplate, "Could not find template file for '#{name}'. Tried all of these: #{possibilities.inspect}"
end
safe_filename(str) click to toggle source

Get a safe-ish filename.

This renders `str` through Mustache and replaces spaces with underscores.

# File lib/pleaserun/platform/base.rb, line 205
def safe_filename(str)
  return render(str).gsub(" ", "_")
end
sysconfig_file() click to toggle source
# File lib/pleaserun/platform/base.rb, line 259
def sysconfig_file
  "/etc/sysconfig/#{name}"
end
template_path() click to toggle source

Get the template path for this platform.

# File lib/pleaserun/platform/base.rb, line 178
def template_path
  return File.join(File.dirname(__FILE__), "../../../templates", platform)
end