Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#with_pid(options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/with_pid.rb', line 4

def with_pid(options)
  # Path to bash script
  bash_path = options[:tmp] + "/" + options[:name]
  
  # Add pid_dir option
  options[:pid_dir] = File.dirname(options[:pid])
  
  # Render bash script
  template = File.dirname(__FILE__) + '/../templates/bash.erb'
  template = File.expand_path(template)
  template = File.read(template)
  template = ERB.new(template).result(binding)
  
  # Write bash script to tmp
  FileUtils.mkdir_p(options[:tmp])
  File.open(bash_path, 'w') do |f|
    f.write(template)
  end
  
  # Execute bash script
  `chmod +x #{bash_path}`
  `#{bash_path}`
end