Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.86.0 (2018-08-13)

* Add options for systemd logging [Lichtamberg]

## 0.85.0 (2018-06-18)

* updates rubies in travis - ensures only running with PID would be killed - updates dependencies; runs `codeclimate-test-reporter` after successful build - updates rubies for travis - squashes commits [LeFnord]
Expand Down
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] %>
1 change: 1 addition & 0 deletions lib/foreman/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def start(process=nil)

method_option :app, :type => :string, :aliases => "-a"
method_option :log, :type => :string, :aliases => "-l"
method_option :error_log, :type => :string, :aliases => "-x"
method_option :run, :type => :string, :aliases => "-r", :desc => "Specify the pid file directory, defaults to /var/run/<application>"
method_option :env, :type => :string, :aliases => "-e", :desc => "Specify an environment file to load, defaults to .env"
method_option :port, :type => :numeric, :aliases => "-p"
Expand Down
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].nil? ? "syslog" : "file:#{options[:log]}"
end

def error_log
options[:error_log].nil? ? "syslog" : "file:#{options[:error_log]}"
end
end
13 changes: 13 additions & 0 deletions spec/foreman/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,17 @@
end
end

describe "export" do
describe "with a valid Procfile" do
it "logs to specified file" do
without_fakefs do
output = foreman("export systemd -f #{resource_path("Procfile")} -l /var/log/foreman.log -x /var/log/foreman.error.log /tmp/foreman-systemd-export")
Dir.glob("/tmp/foreman-systemd-export/*.service").each do |file|
expect(File.read(file)).to match("StandardOutput=file:/var/log/foreman.log")
expect(File.read(file)).to match("StandardError=file:/var/log/foreman.error.log")
end
end
end
end
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/foreman.log", :error_log => "/var/log/foreman.error.log" } }

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

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

Expand Down