mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Updated ulimit warning message to include the recommended min value.
This commit is contained in:
parent
cc958947e5
commit
04fd7ce9e1
1 changed files with 20 additions and 12 deletions
32
main.go
32
main.go
|
@ -95,18 +95,9 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
// Warn if ulimit is too low for production sites
|
||||
if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") &&
|
||||
!addr.IP.IsLoopback() && !checkedFdLimit {
|
||||
out, err := exec.Command("sh", "-c", "ulimit -n").Output() // use sh because ulimit isn't in Linux $PATH
|
||||
if err == nil {
|
||||
// Note that an error here need not be reported
|
||||
lim, err := strconv.Atoi(string(bytes.TrimSpace(out)))
|
||||
if err == nil && lim < 4096 {
|
||||
fmt.Printf("Warning: File descriptor limit is too low (%d) for production sites\n", lim)
|
||||
}
|
||||
checkedFdLimit = true
|
||||
}
|
||||
if !checkedFdLimit && !addr.IP.IsLoopback() {
|
||||
checkFdlimit()
|
||||
checkedFdLimit = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +106,23 @@ func main() {
|
|||
app.Wg.Wait()
|
||||
}
|
||||
|
||||
// checkFdlimit issues a warning if the OS max file descriptors is below a recommended minimum.
|
||||
func checkFdlimit() {
|
||||
const min = 4096
|
||||
|
||||
// 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 {
|
||||
// Note that an error here need not be reported
|
||||
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 sites. Recommend at least ulimit -n %d\n", lim, min)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// isLocalhost returns true if the string looks explicitly like a localhost address.
|
||||
func isLocalhost(s string) bool {
|
||||
return s == "localhost" || s == "::1" || strings.HasPrefix(s, "127.")
|
||||
|
|
Loading…
Reference in a new issue