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

This commit is contained in:
Simon Zolin 2019-03-27 17:09:48 +03:00
parent 92e70515ae
commit 1f1e26f67b
2 changed files with 24 additions and 5 deletions

17
app.go
View File

@ -92,6 +92,11 @@ func run(args options) {
log.Fatal(err) log.Fatal(err)
} }
if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") &&
config.RlimitNoFile != 0 {
setRlimit(config.RlimitNoFile)
}
// override bind host/port from the console // override bind host/port from the console
if args.bindHost != "" { if args.bindHost != "" {
config.BindHost = args.bindHost config.BindHost = args.bindHost
@ -285,6 +290,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() { func cleanup() {
log.Info("Stopping AdGuard Home") log.Info("Stopping AdGuard Home")

View File

@ -39,6 +39,8 @@ type configuration struct {
AuthName string `yaml:"auth_name"` // AuthName is the basic auth username AuthName string `yaml:"auth_name"` // AuthName is the basic auth username
AuthPass string `yaml:"auth_pass"` // AuthPass is the basic auth password AuthPass string `yaml:"auth_pass"` // AuthPass is the basic auth password
Language string `yaml:"language"` // two-letter ISO 639-1 language code Language string `yaml:"language"` // two-letter ISO 639-1 language code
RlimitNoFile uint `yaml:"rlimit_nofile"` // Maximum number of opened fd's per process (0: default)
DNS dnsConfig `yaml:"dns"` DNS dnsConfig `yaml:"dns"`
TLS tlsConfig `yaml:"tls"` TLS tlsConfig `yaml:"tls"`
Filters []filter `yaml:"filters"` Filters []filter `yaml:"filters"`