Class: Cany::Dpkg::DebHelperRecipe

Inherits:
Recipe
  • Object
show all
Defined in:
lib/cany/dpkg/deb_helper_recipe.rb

Instance Attribute Summary

Attributes inherited from Recipe

#inner, #spec

Instance Method Summary collapse

Methods inherited from Recipe

#configure, #depend, #exec, from_name, hook, #hook, #install, #install_content, #install_dir, #install_link, option, #option, #recipe, register_as, #rmtree, #ruby_bin, #run_hook

Methods included from Mixins::DependMixin

#create_dep

Constructor Details

#initialize(*args) ⇒ DebHelperRecipe

Returns a new instance of DebHelperRecipe.



9
10
11
12
13
14
# File 'lib/cany/dpkg/deb_helper_recipe.rb', line 9

def initialize(*args)
  super *args
  @services = {}
  @pre_scripts = []
  @log = File.read debhelper_log if File.exists? debhelper_log
end

Instance Method Details

#binaryObject



38
39
40
41
42
43
44
# File 'lib/cany/dpkg/deb_helper_recipe.rb', line 38

def binary
  instance_eval &spec.binary if spec.binary
  install_base_service
  install_services
  File.write debhelper_log, @log if File.exists? debhelper_log
  exec %w(dh binary)
end

#buildObject



33
34
35
36
# File 'lib/cany/dpkg/deb_helper_recipe.rb', line 33

def build
  instance_eval &spec.build if spec.build
  exec %w(dh build)
end

#cleanObject



28
29
30
31
# File 'lib/cany/dpkg/deb_helper_recipe.rb', line 28

def clean
  instance_eval &spec.clean if spec.clean
  exec %w(dh clean)
end

#create(creator) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/cany/dpkg/deb_helper_recipe.rb', line 16

def create(creator)
  depend 'debhelper', version: '>= 7.0.50~', situation: :build
  depend '${shlibs:Depends}'
  depend '${misc:Depends}'
  depend creator.ruby_deb, situation: [:build, :runtime]
  depend creator.ruby_deb + '-dev', situation: :build
end

#install_base_serviceObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/cany/dpkg/deb_helper_recipe.rb', line 79

def install_base_service
  File.write debian("#{spec.name}.upstart"), render(<<-EOF.gsub(/^ {8}/, ''))
    description "#{spec.description}"

    start on filesystem or runlevel [2345]
    stop on runlevel [!2345]

    respawn
    respawn limit 10 5
    umask 022

    pre-start script
    <% pre_scripts.each do |k, command| %>
      <%= command %>
    <% end %>
    end script

    exec sleep 365d
  EOF
end

#install_service(name, command, opts = {}) ⇒ Object



46
47
48
49
50
# File 'lib/cany/dpkg/deb_helper_recipe.rb', line 46

def install_service(name, command, opts={})
  opts = {user: 'root', group: 'root'}.merge opts
  opts[:command] = command
  @services[name] = opts
end

#install_servicesObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cany/dpkg/deb_helper_recipe.rb', line 52

def install_services
  @services.each do |name, opts|
    File.write debian("#{spec.name}.#{spec.name}-#{name}.upstart"), render(<<-EOF.gsub(/^ {10}/, ''), opts.merge(name: name))
      description "<%= spec.description %> - <%= name %>"

      start on started <%= spec.name %>
      stop on stopping <%= spec.name %>

      respawn
      respawn limit 10 5
      umask 022

      chdir /usr/share/<%= spec.name %>

      <% if user %>
      setuid <%= user %>
      <% end %>
      <% if group %>
      setgid <%= group %>
      <% end %>

      exec <%= command.join(' ') %>
    EOF
    exec %w{dh_installinit --name}, "#{spec.name}-#{name}"
  end
end

#prepareObject



24
25
26
# File 'lib/cany/dpkg/deb_helper_recipe.rb', line 24

def prepare
  instance_eval &spec.prepare if spec.prepare
end