summaryrefslogtreecommitdiffhomepage
path: root/rlimit_posix.go
blob: e63987767dfef08e44cb14a0f295d99b3ae9b824 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// +build !windows

package caddy

import (
	"fmt"
	"syscall"
)

// checkFdlimit issues a warning if the OS limit for
// max file descriptors is below a recommended minimum.
func checkFdlimit() {
	const min = 8192

	// Warn if ulimit is too low for production sites
	rlimit := &syscall.Rlimit{}
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, rlimit)
	if err == nil && rlimit.Cur < min {
		fmt.Printf("WARNING: File descriptor limit %d is too low for production servers. "+
			"At least %d is recommended. Fix with \"ulimit -n %d\".\n", rlimit.Cur, min, min)
	}

}