Class: FPM::Package::PleaseRun

Inherits:
FPM::Package show all
Defined in:
lib/fpm/package/pleaserun.rb

Overview

A pleaserun package.

This does not currently support 'output'

Instance Attribute Summary

Attributes inherited from FPM::Package

#architecture, #attributes, #attrs, #category, #config_files, #conflicts, #dependencies, #description, #directories, #epoch, #iteration, #license, #maintainer, #name, #provides, #replaces, #scripts, #url, #vendor, #version

Instance Method Summary collapse

Methods inherited from FPM::Package

apply_options, #build_path, #cleanup, #cleanup_build, #cleanup_staging, #convert, #converted_from, default_attributes, #edit_file, #files, inherited, #initialize, option, #output, #script, #staging_path, #to_s, type, #type, types

Methods included from Util

#ar_cmd, #ar_cmd_deterministic?, #copied_entries, #copy_entry, #copy_metadata, #default_shell, #execmd, #expand_pessimistic_constraints, #logger, #mknod_w, #program_exists?, #program_in_path?, #safesystem, #safesystemout, #tar_cmd, #tar_cmd_supports_sort_names_and_set_mtime?

Constructor Details

This class inherits a constructor from FPM::Package

Instance Method Details

#input(command) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fpm/package/pleaserun.rb', line 23

def input(command)
  platforms = [
    ::PleaseRun::Platform::Systemd.new("default"), # RHEL 7, Fedora 19+, Debian 8, Ubuntu 16.04
    ::PleaseRun::Platform::Upstart.new("1.5"), # Recent Ubuntus
    ::PleaseRun::Platform::Upstart.new("0.6.5"), # CentOS 6
    ::PleaseRun::Platform::Launchd.new("10.9"), # OS X
    ::PleaseRun::Platform::SYSV.new("lsb-3.1") # Ancient stuff
  ]
  pleaserun_attributes = [ "chdir", "user", "group", "umask", "chroot", "nice", "limit_coredump",
                           "limit_cputime", "limit_data", "limit_file_size", "limit_locked_memory",
                           "limit_open_files", "limit_user_processes", "limit_physical_memory", "limit_stack_size",
                           "log_directory", "log_file_stderr", "log_file_stdout"]

  attributes[:pleaserun_name] ||= File.basename(command.first)
  attributes[:prefix] ||= "/usr/share/pleaserun/#{attributes[:pleaserun_name]}"

  platforms.each do |platform|
    logger.info("Generating service manifest.", :platform => platform.class.name)
    platform.program = command.first
    platform.name = attributes[:pleaserun_name]
    platform.args = command[1..-1]
    platform.description = if attributes[:description_given?]
      attributes[:description]
    else
      platform.name
    end
    pleaserun_attributes.each do |attribute_name|
      attribute = "pleaserun_#{attribute_name}".to_sym
      if attributes.has_key?(attribute) and not attributes[attribute].nil?
        platform.send("#{attribute_name}=", attributes[attribute])
      end
    end

    base = staging_path(File.join(attributes[:prefix], "#{platform.platform}/#{platform.target_version || "default"}"))
    target = File.join(base, "files")
    actions_script = File.join(base, "install_actions.sh")
    ::PleaseRun::Installer.install_files(platform, target, false)
    ::PleaseRun::Installer.write_actions(platform, actions_script)
  end

  libs = [ "install.sh", "install-path.sh", "generate-cleanup.sh" ]
  libs.each do |file|
    base = staging_path(File.join(attributes[:prefix]))
    File.write(File.join(base, file), template(File.join("pleaserun", file)).result(binding))
    File.chmod(0755, File.join(base, file))
  end

  scripts[:after_install] = template(File.join("pleaserun", "scripts", "after-install.sh")).result(binding)
  scripts[:before_remove] = template(File.join("pleaserun", "scripts", "before-remove.sh")).result(binding)
end