summaryrefslogtreecommitdiff
path: root/acceptance/data-collector/.acceptance/data-collector-test/recipes/default.rb
blob: 2ba4fe81fce7ffbca1dd53ffb330f6c5b2ec3dfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

oldpath = ENV["PATH"]
ENV["PATH"] = "/opt/chef/embedded/bin:#{ENV["PATH"]}"

api_root_dir = "/var/opt/data_collector_api"

directory api_root_dir do
  recursive true
end

cookbook_file ::File.join(api_root_dir, "Gemfile") do
  source "apigemfile"
end

cookbook_file ::File.join(api_root_dir, "config.ru")

cookbook_file ::File.join(api_root_dir, "api.rb")

execute "bundle install --binstubs" do
  cwd api_root_dir
end

pid_file    = "/var/run/api.pid"
running_pid = ::File.exist?(pid_file) ? ::File.read(pid_file).strip : nil

execute "kill existing API process" do
  command "kill #{running_pid}"
  not_if { running_pid.nil? }
end

execute "start API" do
  command "bin/rackup -D -P #{pid_file}"
  cwd api_root_dir
end

directory "/etc/chef"

["both-mode", "client-mode", "no-endpoint", "solo-mode"].each do |config_file|
  cookbook_file "/etc/chef/#{config_file}.rb" do
    source "client-rb-#{config_file}.rb"
  end
end

ENV["PATH"] = oldpath