diff --git a/caddy.go b/caddy.go index 401c6fc6f..1b1caf54d 100644 --- a/caddy.go +++ b/caddy.go @@ -21,8 +21,6 @@ import ( "log" "net" "os" - "os/exec" - "runtime" "strconv" "strings" "sync" @@ -725,24 +723,6 @@ func IsLoopback(addr string) bool { strings.HasPrefix(host, "127.") } -// 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 - if runtime.GOOS == "linux" || runtime.GOOS == "darwin" { - out, err := exec.Command("sh", "-c", "ulimit -n").Output() // use sh because ulimit isn't in Linux $PATH - if err == nil { - lim, err := strconv.Atoi(string(bytes.TrimSpace(out))) - if err == nil && lim < 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", lim, min, min) - } - } - } -} - // Upgrade re-launches the process, preserving the listeners // for a graceful restart. It does NOT load new configuration; // it only starts the process anew with a fresh binary. diff --git a/rlimit_posix.go b/rlimit_posix.go new file mode 100644 index 000000000..e63987767 --- /dev/null +++ b/rlimit_posix.go @@ -0,0 +1,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) + } + +} diff --git a/rlimit_windows.go b/rlimit_windows.go new file mode 100644 index 000000000..0288102f5 --- /dev/null +++ b/rlimit_windows.go @@ -0,0 +1,6 @@ +package caddy + +// checkFdlimit issues a warning if the OS limit for +// max file descriptors is below a recommended minimum. +func checkFdlimit() { +}