diff --git a/Changelog.md b/Changelog.md index 259b8b2b..9039ddb1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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] diff --git a/data/export/systemd/process.service.erb b/data/export/systemd/process.service.erb index 148cbe79..50214199 100644 --- a/data/export/systemd/process.service.erb +++ b/data/export/systemd/process.service.erb @@ -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] %> diff --git a/lib/foreman/cli.rb b/lib/foreman/cli.rb index 49f0377d..52d62fb8 100644 --- a/lib/foreman/cli.rb +++ b/lib/foreman/cli.rb @@ -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/" method_option :env, :type => :string, :aliases => "-e", :desc => "Specify an environment file to load, defaults to .env" method_option :port, :type => :numeric, :aliases => "-p" diff --git a/lib/foreman/export/systemd.rb b/lib/foreman/export/systemd.rb index 0f828d55..d293185f 100644 --- a/lib/foreman/export/systemd.rb +++ b/lib/foreman/export/systemd.rb @@ -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 diff --git a/spec/foreman/cli_spec.rb b/spec/foreman/cli_spec.rb index b8c3cfee..c92fe3fe 100644 --- a/spec/foreman/cli_spec.rb +++ b/spec/foreman/cli_spec.rb @@ -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 diff --git a/spec/foreman/export/systemd_spec.rb b/spec/foreman/export/systemd_spec.rb index 768137ab..64140288 100644 --- a/spec/foreman/export/systemd_spec.rb +++ b/spec/foreman/export/systemd_spec.rb @@ -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" }