procfile-upstart-exporter 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d2d1e53d73c1d9c485b125698e2e0ab41528de6
4
- data.tar.gz: 4f13e9cb6eee0144dfb49ea5a000606b2403533d
3
+ metadata.gz: 429328d9f681e98dd3566923a98cf7e3540c3b73
4
+ data.tar.gz: 60e80f223088d9b05bed18f788bc827b1fa8462e
5
5
  SHA512:
6
- metadata.gz: 9ea702b920af27f119b7266aabc033b72ea4f809621fc2fc57c1f7aae53b6a806ab4b5fdd191bf1925ab19787e3878bab6d8056f823c969ce2c5082feb3afcc9
7
- data.tar.gz: 343a676082a37552fee0982068e24233ac63dd64c8560b19e5ceddda96bc269e4e70c198e978e1c2c7f79f8221695d1c1807a73e299ae81275f5dcacc1fbbbff
6
+ metadata.gz: f94f32034c86751266ff7aa09e3c4481910b000268636bae74518878d9db092e586e1bfc8d90112031f9ce8779b73a0f6623231f16d796fb4858f01cc5112df2
7
+ data.tar.gz: a45d1ff7faf10e50b7822f5a22edc1b73c9341f1b0ee7af4fa79021a990620d7873479211c69229ad0c274c2decde2c13f57066c0f16b4815c65584aca8be71e
data/README.md CHANGED
@@ -72,6 +72,11 @@ Usage
72
72
  Changelog
73
73
  ---------
74
74
 
75
+ ### `v0.0.3`
76
+
77
+ - Fix logging in job destruction.
78
+ - Only stop and destroy needed jobs.
79
+
75
80
  ### `v0.0.2`
76
81
 
77
82
  - Warn if `Procfile` or `.env` don't exist.
@@ -18,7 +18,8 @@ class ProcfileUpstartExporter::Cli < Thor
18
18
  option :user, default: 'app'
19
19
  option :path, default: '/etc/init'
20
20
  def create
21
- destroy
21
+ enter_verbose_mode if options[:verbose]
22
+ destroyer.destroy options[:application], options[:path], options[:procfile]
22
23
  creator.create options[:application],
23
24
  options[:procfile],
24
25
  options[:log],
@@ -1,12 +1,41 @@
1
1
  class ProcfileUpstartExporter::Destroyer
2
- def destroy application, path
3
- ProcfileUpstartExporter.logger.debug 'Starting Upstart jobs deletion'
2
+ def initialize procfile_parser = ProcfileUpstartExporter::ProcfileParser.new
3
+ self.procfile_parser = procfile_parser
4
+ end
5
+
6
+ def destroy application, path, procfile = nil
7
+ ProcfileUpstartExporter.logger.debug 'Starting Upstart jobs deletion ' \
4
8
  "for `#{ application }'"
9
+ if procfile
10
+ destroy_jobs application, path, procfile_parser.parse(procfile)
11
+ .map(&:name)
12
+ else
13
+ destroy_all_jobs application, path
14
+ end
15
+ ProcfileUpstartExporter.logger.debug 'Deleted Upstart jobs for ' \
16
+ "`#{ application }'"
17
+ end
18
+
19
+ private
20
+
21
+ attr_accessor :procfile_parser
22
+
23
+ def destroy_all_jobs application, path
5
24
  stopping_output = IO.popen(['stop', application], err: [:child, :out]).read
6
25
  ProcfileUpstartExporter.logger.debug stopping_output
7
26
  FileUtils.rm_rf File.join(path, "#{ application }.conf")
8
27
  FileUtils.rm_rf File.join(path, application)
9
- ProcfileUpstartExporter.logger.debug 'Deleted Upstart jobs for ' \
10
- "`#{ application }'"
28
+ end
29
+
30
+ def destroy_jobs application, path, processes_names
31
+ Dir.glob("#{ path }/#{ application }/*.conf").each do |job_absolute_path|
32
+ process_name = File.basename job_absolute_path, '.conf'
33
+ unless processes_names.include? process_name
34
+ job = File.join application, process_name
35
+ stopping_output = IO.popen(['stop', job], err: [:child, :out]).read
36
+ ProcfileUpstartExporter.logger.debug stopping_output
37
+ FileUtils.rm_rf File.join(path, "#{ job }.conf")
38
+ end
39
+ end
11
40
  end
12
41
  end
@@ -1,3 +1,3 @@
1
1
  module ProcfileUpstartExporter
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -11,6 +11,13 @@ describe ProcfileUpstartExporter::Creator do
11
11
  let(:process_job_renderer) { double }
12
12
 
13
13
  describe '#create' do
14
+ subject(:create) {
15
+ Dir.chdir 'spec/fixtures/sample-application' do
16
+ creator.create application, procfile, log, environment, user,
17
+ upstart_jobs_path
18
+ end
19
+ }
20
+
14
21
  let(:application) { 'application' }
15
22
  let(:procfile) { 'Procfile' }
16
23
  let(:log) { "#{ temp_dir }/log" }
@@ -37,13 +44,6 @@ describe ProcfileUpstartExporter::Creator do
37
44
  )
38
45
  }
39
46
 
40
- let(:act) {
41
- Dir.chdir 'spec/fixtures/sample-application' do
42
- creator.create application, procfile, log, environment, user,
43
- upstart_jobs_path
44
- end
45
- }
46
-
47
47
  before do
48
48
  allow(procfile_parser).to receive(:parse)
49
49
  .and_return [web_process, background_process]
@@ -73,14 +73,14 @@ JOB_CONFIGURATION
73
73
  end
74
74
 
75
75
  it 'creates an Upstart job for the application' do
76
- act
76
+ create
77
77
  expect(
78
78
  File.exists? "#{ upstart_jobs_path }/#{ application }.conf"
79
79
  ).to be_true
80
80
  end
81
81
 
82
82
  it 'renders the Upstart job template for each process in Procfile' do
83
- act
83
+ create
84
84
  expect(
85
85
  File.read "#{ upstart_jobs_path }/#{ application }/web.conf"
86
86
  ).to match 'bundle exec rails server -p 5000'
@@ -91,12 +91,12 @@ JOB_CONFIGURATION
91
91
 
92
92
  it 'creates a folder for logging owned by the user' do
93
93
  expect(FileUtils).to receive(:chown).with(user, user, application_log)
94
- act
94
+ create
95
95
  expect(File.directory? application_log).to be_true
96
96
  end
97
97
 
98
98
  it "places environment variables from environment file in Upstart job" do
99
- act
99
+ create
100
100
  expect(
101
101
  File.read("#{ upstart_jobs_path }/#{ application }/background.conf")
102
102
  ).to match 'RAILS_ENV=production'
@@ -1,37 +1,84 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ProcfileUpstartExporter::Destroyer do
4
- subject(:destroyer) { ProcfileUpstartExporter::Destroyer.new }
4
+ subject(:destroyer) {
5
+ ProcfileUpstartExporter::Destroyer.new procfile_parser
6
+ }
7
+
8
+ let(:procfile_parser) { double }
5
9
 
6
10
  describe '#destroy' do
7
- let(:application) { 'application' }
8
- let(:path) { temp_dir }
9
- let(:application_path) { "#{ path }/#{ application }" }
10
- let(:application_job) { "#{ path }/#{ application }.conf" }
11
- let(:process_job) { "#{ path }/#{ application }/web.conf" }
12
-
13
- let(:act) {
14
- destroyer.destroy application, path
11
+ subject(:destroy) {
12
+ destroyer.destroy application, path, procfile
15
13
  }
16
14
 
15
+ let(:application) { 'application' }
16
+ let(:path) { temp_dir }
17
+ let(:procfile) { nil }
18
+ let(:application_path) { "#{ path }/#{ application }" }
19
+ let(:application_job) { "#{ path }/#{ application }.conf" }
20
+ let(:web_job) { "#{ path }/#{ application }/web.conf" }
21
+ let(:background_job) { "#{ path }/#{ application }/background.conf" }
22
+
17
23
  before do
18
24
  FileUtils.mkdir_p application_path
19
25
  FileUtils.touch application_job
20
- FileUtils.touch process_job
21
- allow(Kernel).to receive(:system)
26
+ FileUtils.touch web_job
27
+ FileUtils.touch background_job
28
+ allow(IO).to receive(:popen).and_call_original
22
29
  end
23
30
 
24
31
  it 'stops the jobs' do
25
32
  expect(IO).to receive(:popen).with(['stop', application],
26
33
  err: [:child, :out]).and_call_original
27
- act
34
+ destroy
28
35
  end
29
36
 
30
37
  it 'deletes Upstart jobs' do
31
- act
32
- [application_path, application_job, process_job].each do |path|
38
+ destroy
39
+ [
40
+ application_path,
41
+ application_job,
42
+ web_job,
43
+ background_job
44
+ ].each do |path|
33
45
  expect(File.exists? path).to be_false
34
46
  end
35
47
  end
48
+
49
+ context 'a Procfile is given' do
50
+ let(:procfile) { 'Procfile' }
51
+ let(:web_process) {
52
+ ProcfileUpstartExporter::Process.with(
53
+ name: 'web',
54
+ command: 'bundle exec rails server -p 5000'
55
+ )
56
+ }
57
+
58
+ before do
59
+ allow(procfile_parser).to receive(:parse)
60
+ .with(procfile)
61
+ .and_return([web_process])
62
+ end
63
+
64
+ it 'only stops the processes not present in the Procfile' do
65
+ expect(IO).to receive(:popen)
66
+ .with(['stop', "#{ application }/background"],
67
+ err: [:child, :out]).and_call_original
68
+ destroy
69
+ end
70
+
71
+ it 'only deletes the jobs not present in the Procfile' do
72
+ destroy
73
+ expect(File.exists? background_job).to be_false
74
+ [
75
+ application_path,
76
+ application_job,
77
+ web_job
78
+ ].each do |path|
79
+ expect(File.exists? path).to be_true
80
+ end
81
+ end
82
+ end
36
83
  end
37
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procfile-upstart-exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Das Dad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-18 00:00:00.000000000 Z
11
+ date: 2013-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor