Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added LimitNOFILE option in systemd configuration #94

Merged
merged 2 commits into from
Jun 7, 2020

Conversation

SimonBackx
Copy link
Contributor

For servers it's important to have an option to set the maximum open files. Simply adding this in /etc/security/limits.conf won't work because systemd ignores this file. Systemd has an option to set LimitNOFILE in the configuration file, so I added this option.

-- end pull info --

I also tried to solve the systemd spaces in paths issues (#63 , #90 ). I tried using the systemd-escape command (instead of the cmd, cmdEscape template functions). But this didn't worked. Seems like they did change the space handing between different versions of systemd.

service_linux.go:

var tf = map[string]interface{}{
	"cmd": func(s string) string {
		return `"` + strings.Replace(s, `"`, `\"`, -1) + `"`
	},
	"cmdEscape": func(s string) string {
		return strings.Replace(s, " ", `\x20`, -1)
	},
	"systemdEscape": func(s string) string {
		// run systemd-escape command to escape paths properly
		// if something goes wrong we'll default to the original string
		cmd := exec.Command("systemd-escape", "--path", s)

		// Connect pipe to read stdout
		stdout, err := cmd.StdoutPipe()

		if err != nil {
			// Failed to connect pipe
			return s
		}

		// Do not use cmd.Run()
		if err := cmd.Start(); err != nil {
			// Problem while copying stdin, stdout, or stderr
			return s
		}

		slurp, _ := ioutil.ReadAll(stdout)

		if err := cmd.Wait(); err != nil {
			// Command didn't exit with a zero exit status.
			return s
		}

		return string(slurp)
	},
}

However, I did found a solution for #90

service_systemd_linux.go (line 165)

ExecStart=/usr/bin/env "{{.Path}}"{{range .Arguments}} {{.|cmd}}{{end}}

Setting the ExecStart option that way should solve the problem, but this needs more testing.
More info: systemd/systemd#2132

morfien101 added a commit to morfien101/service that referenced this pull request Oct 15, 2019
@kardianos kardianos merged commit a1c091b into kardianos:master Jun 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants