From e435b83b46605cc365689a49dda2dc813506a246 Mon Sep 17 00:00:00 2001 From: Cody Gibb Date: Wed, 7 Oct 2020 13:30:36 -0700 Subject: [PATCH] Allow overriding nginx stdout log path (#282) --- nginx/nginx.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nginx/nginx.go b/nginx/nginx.go index 2cbacd75a..3133ecdac 100644 --- a/nginx/nginx.go +++ b/nginx/nginx.go @@ -52,6 +52,7 @@ type Config struct { LogDir string `yaml:"log_dir"` // Optional log path overrides. + StdoutLogPath string `yaml:"stdout_log_path"` AccessLogPath string `yaml:"access_log_path"` ErrorLogPath string `yaml:"error_log_path"` @@ -62,6 +63,12 @@ func (c *Config) applyDefaults() error { if c.Binary == "" { c.Binary = "/usr/sbin/nginx" } + if c.StdoutLogPath == "" { + if c.LogDir == "" { + return errors.New("one of log_dir or stdout_log_path must be set") + } + c.StdoutLogPath = filepath.Join(c.LogDir, "nginx-stdout.log") + } if c.AccessLogPath == "" { if c.LogDir == "" { return errors.New("one of log_dir or access_log_path must be set") @@ -208,8 +215,7 @@ func Run(config Config, params map[string]interface{}, opts ...Option) error { return fmt.Errorf("write src: %s", err) } - stdoutLog := path.Join(config.LogDir, "nginx-stdout.log") - stdout, err := os.OpenFile(stdoutLog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + stdout, err := os.OpenFile(config.StdoutLogPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { return fmt.Errorf("open stdout log: %s", err) }