foreman 0.86.0 → 0.87.0

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
  SHA256:
3
- metadata.gz: 31de74ed070d8e9aaf047c043b381096f56b7841262ebe470ff9fe3795e17c5c
4
- data.tar.gz: 4e767f27609093c4601d0fc585700b31dcc69d253309fe3ce602b4c523a9d9e9
3
+ metadata.gz: b4561719e71efe2d57cb77e271499273d03dd6e3ce1566c2ea448b9924f3986b
4
+ data.tar.gz: 317cb62ea6013742326098d8e4942aafaed4f3c8ba1eee63bf52c269c514d3b8
5
5
  SHA512:
6
- metadata.gz: 4ea65399799e00fe1fd61511d48484210b1963ce1f89ed324ac57f797c4c08782ee6f9fa58029941e0796037fd9ed2d478758d200a30ced898aa0aa7ac56ec40
7
- data.tar.gz: e119d9e76d43f25817462923ff1ff85bd8dfcad7c5bd9ab3efccaa726a7afbe5952c927c9ecbc0eb16edc9b5eb151b774985ce593e175d6efbe0ac1867dc1da5
6
+ metadata.gz: 5af45a820751188c14a474634687b8a088aa436c0de20cf828e1ced1f3c4cdec51da0f6e1566dc78a0f04faa1f14c8a5e516005d96a0abc3c5833e689dd2d217
7
+ data.tar.gz: a35df2258df75633fdeb5835e5f6d82290be0c7c573fac3b2da482c9d61565db7acea6e80c6d1b0663b11924b825139502c0553d231f941a2fa0033cf7cee85a
@@ -1,5 +1,5 @@
1
1
  [Unit]
2
- Wants=<%= process_master_names.join(' ') %>
2
+ Wants=<%= service_names.join(' ') %>
3
3
 
4
4
  [Install]
5
5
  WantedBy=multi-user.target
@@ -1,15 +1,18 @@
1
1
  [Unit]
2
- PartOf=<%= app %>-<%= name %>.target
2
+ PartOf=<%= app %>.target
3
+ StopWhenUnneeded=yes
3
4
 
4
5
  [Service]
5
6
  User=<%= user %>
6
7
  WorkingDirectory=<%= engine.root %>
7
- Environment=PORT=%i
8
+ Environment=PORT=<%= port %>
9
+ Environment=PS=<%= process_name %>
8
10
  <% engine.env.each_pair do |var,env| -%>
9
11
  Environment="<%= var %>=<%= env %>"
10
12
  <% end -%>
11
- ExecStart=/bin/bash -lc 'exec <%= process.command %>'
13
+ ExecStart=/bin/bash -lc 'exec -a "<%= app %>-<%= process_name %>" <%= process.command %>'
12
14
  Restart=always
15
+ RestartSec=14s
13
16
  StandardInput=null
14
17
  StandardOutput=syslog
15
18
  StandardError=syslog
@@ -17,22 +17,16 @@ class Foreman::Export::Systemd < Foreman::Export::Base
17
17
  clean_dir file
18
18
  end
19
19
 
20
- process_master_names = []
20
+ service_names = []
21
21
 
22
22
  engine.each_process do |name, process|
23
- service_fn = "#{app}-#{name}@.service"
24
- write_template "systemd/process.service.erb", service_fn, binding
25
-
26
- create_directory("#{app}-#{name}.target.wants")
27
- 1.upto(engine.formation[name])
28
- .collect { |num| engine.port_for(process, num) }
29
- .collect { |port| "#{app}-#{name}@#{port}.service" }
30
- .each do |process_name|
31
- create_symlink("#{app}-#{name}.target.wants/#{process_name}", "../#{service_fn}") rescue Errno::EEXIST # This is needed because rr-mocks do not call the origial cleanup
23
+ 1.upto(engine.formation[name]) do |num|
24
+ port = engine.port_for(process, num)
25
+ process_name = "#{name}.#{num}"
26
+ service_filename = "#{app}-#{process_name}.service"
27
+ write_template "systemd/process.service.erb", service_filename, binding
28
+ service_names << service_filename
32
29
  end
33
-
34
- write_template "systemd/process_master.target.erb", "#{app}-#{name}.target", binding
35
- process_master_names << "#{app}-#{name}.target"
36
30
  end
37
31
 
38
32
  write_template "systemd/master.target.erb", "#{app}.target", binding
@@ -1,5 +1,5 @@
1
1
  module Foreman
2
2
 
3
- VERSION = "0.86.0"
3
+ VERSION = "0.87.0"
4
4
 
5
5
  end
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "FOREMAN" "1" "July 2019" "Foreman 0.86.0" "Foreman Manual"
4
+ .TH "FOREMAN" "1" "January 2020" "Foreman 0.87.0" "Foreman Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBforeman\fR \- manage Procfile\-based applications
@@ -3,7 +3,7 @@ require "foreman/engine"
3
3
  require "foreman/export/systemd"
4
4
  require "tmpdir"
5
5
 
6
- describe Foreman::Export::Systemd, :fakefs do
6
+ describe Foreman::Export::Systemd, :fakefs, :aggregate_failures do
7
7
  let(:procfile) { write_procfile("/tmp/app/Procfile") }
8
8
  let(:formation) { nil }
9
9
  let(:engine) { Foreman::Engine.new(:formation => formation).load_procfile(procfile) }
@@ -16,71 +16,101 @@ describe Foreman::Export::Systemd, :fakefs do
16
16
  it "exports to the filesystem" do
17
17
  systemd.export
18
18
 
19
- expect(File.read("/tmp/init/app.target")).to eq(example_export_file("systemd/app.target"))
20
- expect(File.read("/tmp/init/app-alpha.target")).to eq(example_export_file("systemd/app-alpha.target"))
21
- expect(File.read("/tmp/init/app-alpha@.service")).to eq(example_export_file("systemd/app-alpha@.service"))
22
- expect(File.read("/tmp/init/app-bravo.target")).to eq(example_export_file("systemd/app-bravo.target"))
23
- expect(File.read("/tmp/init/app-bravo@.service")).to eq(example_export_file("systemd/app-bravo@.service"))
24
-
25
- expect(File.directory?("/tmp/init/app-alpha.target.wants")).to be_truthy
26
- expect(File.symlink?("/tmp/init/app-alpha.target.wants/app-alpha@5000.service")).to be_truthy
19
+ expect(File.read("/tmp/init/app.target")).to eq(example_export_file("systemd/app.target"))
20
+ expect(File.read("/tmp/init/app-alpha.1.service")).to eq(example_export_file("systemd/app-alpha.1.service"))
21
+ expect(File.read("/tmp/init/app-bravo.1.service")).to eq(example_export_file("systemd/app-bravo.1.service"))
27
22
  end
28
23
 
29
- it "cleans up if exporting into an existing dir" do
30
- expect(FileUtils).to receive(:rm).with("/tmp/init/app.target")
24
+ context "when systemd export was run using the previous version of systemd export" do
25
+ before do
26
+ write_file("/tmp/init/app.target")
31
27
 
32
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha@.service")
33
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha.target")
34
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha.target.wants/app-alpha@5000.service")
35
- expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-alpha.target.wants")
28
+ write_file("/tmp/init/app-alpha@.service")
29
+ write_file("/tmp/init/app-alpha.target")
30
+ write_file("/tmp/init/app-alpha.target.wants/app-alpha@5000.service")
36
31
 
37
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo.target")
38
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo@.service")
39
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo.target.wants/app-bravo@5100.service")
40
- expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-bravo.target.wants")
32
+ write_file("/tmp/init/app-bravo.target")
33
+ write_file("/tmp/init/app-bravo@.service")
34
+ write_file("/tmp/init/app-bravo.target.wants/app-bravo@5100.service")
41
35
 
42
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar.target")
43
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar@.service")
44
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar.target.wants/app-foo_bar@5200.service")
45
- expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-foo_bar.target.wants")
36
+ write_file("/tmp/init/app-foo_bar.target")
37
+ write_file("/tmp/init/app-foo_bar@.service")
38
+ write_file("/tmp/init/app-foo_bar.target.wants/app-foo_bar@5200.service")
46
39
 
47
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar.target")
48
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar@.service")
49
- expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar.target.wants/app-foo-bar@5300.service")
50
- expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-foo-bar.target.wants")
40
+ write_file("/tmp/init/app-foo-bar.target")
41
+ write_file("/tmp/init/app-foo-bar@.service")
42
+ write_file("/tmp/init/app-foo-bar.target.wants/app-foo-bar@5300.service")
43
+ end
51
44
 
45
+ it "cleans up service files created by systemd export" do
46
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app.target")
52
47
 
53
- systemd.export
54
- systemd.export
48
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha@.service")
49
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha.target")
50
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha.target.wants/app-alpha@5000.service")
51
+ expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-alpha.target.wants")
52
+
53
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo.target")
54
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo@.service")
55
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo.target.wants/app-bravo@5100.service")
56
+ expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-bravo.target.wants")
57
+
58
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar.target")
59
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar@.service")
60
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar.target.wants/app-foo_bar@5200.service")
61
+ expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-foo_bar.target.wants")
62
+
63
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar.target")
64
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar@.service")
65
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar.target.wants/app-foo-bar@5300.service")
66
+ expect(FileUtils).to receive(:rm_r).with("/tmp/init/app-foo-bar.target.wants")
67
+
68
+ systemd.export
69
+ end
70
+ end
71
+
72
+ context "when systemd export was run using the current version of systemd export" do
73
+ before do
74
+ systemd.export
75
+ end
76
+
77
+ it "cleans up service files created by systemd export" do
78
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app.target")
79
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha.1.service")
80
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo.1.service")
81
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar.1.service")
82
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar.1.service")
83
+
84
+ systemd.export
85
+ end
55
86
  end
56
87
 
57
88
  it "includes environment variables" do
58
89
  engine.env['KEY'] = 'some "value"'
59
90
  systemd.export
60
- expect(File.read("/tmp/init/app-alpha@.service")).to match(/KEY=some "value"/)
91
+ expect(File.read("/tmp/init/app-alpha.1.service")).to match(/KEY=some "value"/)
61
92
  end
62
93
 
63
94
  it "includes ExecStart line" do
64
95
  engine.env['KEY'] = 'some "value"'
65
96
  systemd.export
66
- expect(File.read("/tmp/init/app-alpha@.service")).to match(/^ExecStart=/)
97
+ expect(File.read("/tmp/init/app-alpha.1.service")).to match(/^ExecStart=/)
67
98
  end
68
99
 
69
- context "with a formation" do
100
+ context "with a custom formation specified" do
70
101
  let(:formation) { "alpha=2" }
71
102
 
72
- it "exports to the filesystem with concurrency" do
103
+ it "exports only those services that are specified in the formation" do
73
104
  systemd.export
74
105
 
75
- expect(File.read("/tmp/init/app.target")).to eq(example_export_file("systemd/app.target"))
76
- expect(File.read("/tmp/init/app-alpha.target")).to eq(example_export_file("systemd/app-alpha.target"))
77
- expect(File.read("/tmp/init/app-alpha@.service")).to eq(example_export_file("systemd/app-alpha@.service"))
78
- expect(File.read("/tmp/init/app-bravo.target")).to eq(example_export_file("systemd/app-bravo.target"))
79
- expect(File.read("/tmp/init/app-bravo@.service")).to eq(example_export_file("systemd/app-bravo@.service"))
106
+ expect(File.read("/tmp/init/app.target")).to include("Wants=app-alpha.1.service app-alpha.2.service\n")
107
+ expect(File.read("/tmp/init/app-alpha.1.service")).to eq(example_export_file("systemd/app-alpha.1.service"))
108
+ expect(File.read("/tmp/init/app-alpha.2.service")).to eq(example_export_file("systemd/app-alpha.2.service"))
109
+ expect(File.exist?("/tmp/init/app-bravo.1.service")).to be_falsey
80
110
  end
81
111
  end
82
112
 
83
- context "with alternate templates" do
113
+ context "with alternate template directory specified" do
84
114
  let(:template) { "/tmp/alternate" }
85
115
  let(:options) { { :app => "app", :template => template } }
86
116
 
@@ -89,25 +119,37 @@ describe Foreman::Export::Systemd, :fakefs do
89
119
  File.open("#{template}/master.target.erb", "w") { |f| f.puts "alternate_template" }
90
120
  end
91
121
 
92
- it "can export with alternate template files" do
122
+ it "uses template files found in the alternate directory" do
93
123
  systemd.export
94
124
  expect(File.read("/tmp/init/app.target")).to eq("alternate_template\n")
95
125
  end
96
- end
97
126
 
98
- context "with alternate templates from home dir" do
127
+ context "with alternate templates in the user home directory" do
128
+ before do
129
+ FileUtils.mkdir_p File.expand_path("~/.foreman/templates/systemd")
130
+ File.open(File.expand_path("~/.foreman/templates/systemd/master.target.erb"), "w") do |file|
131
+ file.puts "home_dir_template"
132
+ end
133
+ end
134
+
135
+ it "uses template files found in the alternate directory" do
136
+ systemd.export
137
+ expect(File.read("/tmp/init/app.target")).to eq("alternate_template\n")
138
+ end
139
+ end
140
+ end
99
141
 
142
+ context "with alternate templates in the user home directory" do
100
143
  before do
101
144
  FileUtils.mkdir_p File.expand_path("~/.foreman/templates/systemd")
102
145
  File.open(File.expand_path("~/.foreman/templates/systemd/master.target.erb"), "w") do |file|
103
- file.puts "default_alternate_template"
146
+ file.puts "home_dir_template"
104
147
  end
105
148
  end
106
149
 
107
- it "can export with alternate template files" do
150
+ it "uses template files found in the user home directory" do
108
151
  systemd.export
109
- expect(File.read("/tmp/init/app.target")).to eq("default_alternate_template\n")
152
+ expect(File.read("/tmp/init/app.target")).to eq("home_dir_template\n")
110
153
  end
111
154
  end
112
-
113
155
  end
@@ -1,12 +1,15 @@
1
1
  [Unit]
2
- PartOf=app-alpha.target
2
+ PartOf=app.target
3
+ StopWhenUnneeded=yes
3
4
 
4
5
  [Service]
5
6
  User=app
6
7
  WorkingDirectory=/tmp/app
7
- Environment=PORT=%i
8
- ExecStart=/bin/bash -lc 'exec ./alpha'
8
+ Environment=PORT=5000
9
+ Environment=PS=alpha.1
10
+ ExecStart=/bin/bash -lc 'exec -a "app-alpha.1" ./alpha'
9
11
  Restart=always
12
+ RestartSec=14s
10
13
  StandardInput=null
11
14
  StandardOutput=syslog
12
15
  StandardError=syslog
@@ -1,12 +1,15 @@
1
1
  [Unit]
2
- PartOf=app-bravo.target
2
+ PartOf=app.target
3
+ StopWhenUnneeded=yes
3
4
 
4
5
  [Service]
5
6
  User=app
6
7
  WorkingDirectory=/tmp/app
7
- Environment=PORT=%i
8
- ExecStart=/bin/bash -lc 'exec ./bravo'
8
+ Environment=PORT=5001
9
+ Environment=PS=alpha.2
10
+ ExecStart=/bin/bash -lc 'exec -a "app-alpha.2" ./alpha'
9
11
  Restart=always
12
+ RestartSec=14s
10
13
  StandardInput=null
11
14
  StandardOutput=syslog
12
15
  StandardError=syslog
@@ -0,0 +1,18 @@
1
+ [Unit]
2
+ PartOf=app.target
3
+ StopWhenUnneeded=yes
4
+
5
+ [Service]
6
+ User=app
7
+ WorkingDirectory=/tmp/app
8
+ Environment=PORT=5100
9
+ Environment=PS=bravo.1
10
+ ExecStart=/bin/bash -lc 'exec -a "app-bravo.1" ./bravo'
11
+ Restart=always
12
+ RestartSec=14s
13
+ StandardInput=null
14
+ StandardOutput=syslog
15
+ StandardError=syslog
16
+ SyslogIdentifier=%n
17
+ KillMode=mixed
18
+ TimeoutStopSec=5
@@ -1,5 +1,5 @@
1
1
  [Unit]
2
- Wants=app-alpha.target app-bravo.target app-foo_bar.target app-foo-bar.target
2
+ Wants=app-alpha.1.service app-bravo.1.service app-foo_bar.1.service app-foo-bar.1.service
3
3
 
4
4
  [Install]
5
5
  WantedBy=multi-user.target
@@ -105,7 +105,7 @@ end
105
105
  def write_file(file)
106
106
  FileUtils.mkdir_p(File.dirname(file))
107
107
  File.open(file, 'w') do |f|
108
- yield(f)
108
+ yield(f) if block_given?
109
109
  end
110
110
  end
111
111
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.86.0
4
+ version: 0.87.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Dollar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-09 00:00:00.000000000 Z
11
+ date: 2020-01-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Process manager for applications with multiple components
14
14
  email: ddollar@gmail.com
@@ -38,7 +38,6 @@ files:
38
38
  - data/export/supervisord/app.conf.erb
39
39
  - data/export/systemd/master.target.erb
40
40
  - data/export/systemd/process.service.erb
41
- - data/export/systemd/process_master.target.erb
42
41
  - data/export/upstart/master.conf.erb
43
42
  - data/export/upstart/process.conf.erb
44
43
  - data/export/upstart/process_master.conf.erb
@@ -139,10 +138,11 @@ files:
139
138
  - spec/resources/export/runit/app-bravo-1/run
140
139
  - spec/resources/export/supervisord/app-alpha-1.conf
141
140
  - spec/resources/export/supervisord/app-alpha-2.conf
141
+ - spec/resources/export/systemd/app-alpha.1.service
142
+ - spec/resources/export/systemd/app-alpha.2.service
142
143
  - spec/resources/export/systemd/app-alpha.target
143
- - spec/resources/export/systemd/app-alpha@.service
144
+ - spec/resources/export/systemd/app-bravo.1.service
144
145
  - spec/resources/export/systemd/app-bravo.target
145
- - spec/resources/export/systemd/app-bravo@.service
146
146
  - spec/resources/export/systemd/app.target
147
147
  - spec/resources/export/upstart/app-alpha-1.conf
148
148
  - spec/resources/export/upstart/app-alpha-2.conf
@@ -1,2 +0,0 @@
1
- [Unit]
2
- PartOf=<%= app %>.target