0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

Warn if ulimit is too low when serving production sites

This commit is contained in:
Matthew Holt 2015-05-20 20:46:27 -06:00
parent 5e8491cf7f
commit 26bb17337e

24
main.go
View file

@ -9,6 +9,7 @@ import (
"log" "log"
"net" "net"
"os" "os"
"os/exec"
"path" "path"
"runtime" "runtime"
"strconv" "strconv"
@ -86,17 +87,32 @@ func main() {
}(s) }(s)
if !quiet { if !quiet {
for _, config := range configs { var checkedFdLimit bool
fmt.Println(config.Address())
}
for addr, configs := range addresses { for addr, configs := range addresses {
for _, conf := range configs { for _, conf := range configs {
// Print address of site
fmt.Println(conf.Address())
// Note if non-localhost site resolves to loopback interface
if addr.IP.IsLoopback() && !isLocalhost(conf.Host) { if addr.IP.IsLoopback() && !isLocalhost(conf.Host) {
fmt.Printf("Notice: %s is only accessible on this machine (%s)\n", fmt.Printf("Notice: %s is only accessible on this machine (%s)\n",
conf.Host, addr.IP.String()) conf.Host, addr.IP.String())
} }
} }
// Warn if ulimit is too low for production sites
if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") &&
addr.IP.IsLoopback() && !checkedFdLimit {
out, err := exec.Command("ulimit", "-n").Output()
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
}
}
} }
} }
} }