Class: Servitor::EnvdirDeployer

Inherits:
Object
  • Object
show all
Includes:
ChildProcessHelper
Defined in:
lib/deployment/envdir_deployer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ChildProcessHelper

#execute_child_process, #execute_child_process_and_capture_output, included

Constructor Details

#initialize(box, service_name, path, dirname, variables) ⇒ EnvdirDeployer

Returns a new instance of EnvdirDeployer.



7
8
9
10
11
12
13
# File 'lib/deployment/envdir_deployer.rb', line 7

def initialize(box, service_name, path, dirname, variables)
  @service_name = service_name
  @box = box
  @path = path
  @dirname = dirname
  @variables = variables
end

Instance Attribute Details

#boxObject (readonly)

Returns the value of attribute box.



5
6
7
# File 'lib/deployment/envdir_deployer.rb', line 5

def box
  @box
end

#dirnameObject (readonly)

Returns the value of attribute dirname.



5
6
7
# File 'lib/deployment/envdir_deployer.rb', line 5

def dirname
  @dirname
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/deployment/envdir_deployer.rb', line 5

def path
  @path
end

#variablesObject (readonly)

Returns the value of attribute variables.



5
6
7
# File 'lib/deployment/envdir_deployer.rb', line 5

def variables
  @variables
end

Instance Method Details

#deployObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/deployment/envdir_deployer.rb', line 15

def deploy
  # envdir is part of daemontools
  box.ssh('which envdir || sudo apt-get install daemontools',
      :vm_name => @service_name, :ignore_exit_code => true, :capture => true)

  box.ruby(<<-RUBY, :vm_name => @service_name, :sudo => true)
    require 'fileutils'
    envdir = File.join(#{path.inspect}, #{dirname.inspect})
    variables = #{variables.inspect}
    FileUtils.rm_rf(envdir)
    FileUtils.mkdir_p(envdir)
    Dir.chdir(envdir) do
      variables.each do |name, value|
        File.open(name.upcase, 'w') {|f| f.write(value.gsub("\n", 0.chr)) } if value
      end
    end
  RUBY
end