Merge: + config: add "rlimit_nofile" setting - Maximum number of opened fd's per process

* commit '1f1e26f67b00ee4983c65e4e3aabf59a488f687b':
  + config: add "rlimit_nofile" setting - Maximum number of opened fd's per process
This commit is contained in:
Simon Zolin
2019-04-15 18:34:53 +03:00
2 changed files with 24 additions and 5 deletions

17
app.go
View File

@@ -95,6 +95,11 @@ func run(args options) {
log.Fatal(err)
}
if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") &&
config.RlimitNoFile != 0 {
setRlimit(config.RlimitNoFile)
}
// override bind host/port from the console
if args.bindHost != "" {
config.BindHost = args.bindHost
@@ -303,6 +308,18 @@ func enableTLS13() {
}
}
// Set user-specified limit of how many fd's we can use
// https://github.com/AdguardTeam/AdGuardHome/issues/659
func setRlimit(val uint) {
var rlim syscall.Rlimit
rlim.Max = uint64(val)
rlim.Cur = uint64(val)
err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
if err != nil {
log.Error("Setrlimit() failed: %v", err)
}
}
func cleanup() {
log.Info("Stopping AdGuard Home")