Skip to content

Commit

Permalink
Fixes ddollar#709. Add Standard- and StandardError log configuration …
Browse files Browse the repository at this point in the history
…for Systemd
  • Loading branch information
h0jeZvgoxFepBQ2C committed Jul 26, 2018
1 parent c0b178c commit 7992280
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions data/export/systemd/process.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Environment="<%= var %>=<%= env %>"
ExecStart=/bin/bash -lc 'exec <%= process.command %>'
Restart=always
StandardInput=null
StandardOutput=syslog
StandardError=syslog
StandardOutput=<%= log %>
StandardError=<%= error_log %>
SyslogIdentifier=%n
KillMode=mixed
TimeoutStopSec=<%= engine.options[:timeout] %>
8 changes: 8 additions & 0 deletions lib/foreman/export/systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ def export

write_template "systemd/master.target.erb", "#{app}.target", binding
end

def log
options[:log] || "syslog"
end

def error_log
options[:error_log] || "syslog"
end
end
18 changes: 18 additions & 0 deletions spec/foreman/export/systemd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@
expect(File.read("/tmp/init/app-alpha@.service")).to match(/^ExecStart=/)
end

context "with a log setting" do
it "includes StandardOutput line with default value" do
systemd.export
expect(File.read("/tmp/init/app-alpha@.service")).to match("StandardOutput=syslog")
expect(File.read("/tmp/init/app-alpha@.service")).to match("StandardError=syslog")
end

context "with custom options" do
let(:options) { { :log => "/var/log/app-alpha", :error_log => "/var/log/app-alpha_error" } }

it "includes StandardOutput line with given value" do
systemd.export
expect(File.read("/tmp/init/app-alpha@.service")).to match("StandardOutput=/var/log/app-alpha")
expect(File.read("/tmp/init/app-alpha@.service")).to match("StandardError=/var/log/app-alpha_error")
end
end
end

context "with a formation" do
let(:formation) { "alpha=2" }

Expand Down

0 comments on commit 7992280

Please sign in to comment.