From 9192318bc485549c70f154eb9c336968b9a0f33d Mon Sep 17 00:00:00 2001 From: Randy Coburn Date: Tue, 15 Oct 2019 16:17:03 +0200 Subject: [PATCH] pulling in https://github.com/kardianos/service/pull/94 --- service.go | 11 +++++++---- service_systemd_linux.go | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/service.go b/service.go index a1304019..4dd2097c 100644 --- a/service.go +++ b/service.go @@ -78,10 +78,12 @@ const ( optionLogOutput = "LogOutput" optionLogOutputDefault = false - optionRunWait = "RunWait" - optionReloadSignal = "ReloadSignal" - optionPIDFile = "PIDFile" - optionRestart = "Restart" + optionRunWait = "RunWait" + optionReloadSignal = "ReloadSignal" + optionPIDFile = "PIDFile" + optionRestart = "Restart" + optionLimitNOFILE = "LimitNOFILE" + optionLimitNOFILEDefault = -1 // -1 = don't set in configuration optionSuccessExitStatus = "SuccessExitStatus" @@ -141,6 +143,7 @@ type Config struct { // - RunWait func() (wait for SIGNAL) - Do not install signal but wait for this function to return. // - ReloadSignal string () [USR1, ...] - Signal to send on reaload. // - PIDFile string () [/run/prog.pid] - Location of the PID file. + // - LimitNOFILE int - Maximum open files (ulimit -n) (https://serverfault.com/questions/628610/increasing-nproc-for-processes-launched-by-systemd-on-centos-7) // - LogOutput bool (false) - Redirect StdErr & StdOut to files. // - Restart string (always) - How shall service be restarted. // - SuccessExitStatus string () - The list of exit status that shall be considered as successful, diff --git a/service_systemd_linux.go b/service_systemd_linux.go index 99c5e2a8..2a29407f 100644 --- a/service_systemd_linux.go +++ b/service_systemd_linux.go @@ -152,6 +152,7 @@ func (s *systemd) Install() error { Restart string SuccessExitStatus string LogOutput bool + LimitNOFILE int }{ s.Config, path, @@ -161,6 +162,7 @@ func (s *systemd) Install() error { s.Option.string(optionRestart, "always"), s.Option.string(optionSuccessExitStatus, ""), s.Option.bool(optionLogOutput, optionLogOutputDefault), + s.Option.int(optionLimitNOFILE, optionLimitNOFILEDefault), } err = s.template().Execute(f, to) @@ -260,6 +262,7 @@ ExecStart={{.Path|cmdEscape}}{{range .Arguments}} {{.|cmd}}{{end}} {{if .UserName}}User={{.UserName}}{{end}} {{if .ReloadSignal}}ExecReload=/bin/kill -{{.ReloadSignal}} "$MAINPID"{{end}} {{if .PIDFile}}PIDFile={{.PIDFile|cmd}}{{end}} +{{if gt .LimitNOFILE -1 }}LimitNOFILE={{.LimitNOFILE}}{{end}} {{if and .LogOutput .HasOutputFileSupport -}} StandardOutput=file:/var/log/{{.Name}}.out StandardError=file:/var/log/{{.Name}}.err