From 26bb17337e3178e1299188bad4b5acc3b9669b85 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 20 May 2015 20:46:27 -0600 Subject: [PATCH] Warn if ulimit is too low when serving production sites --- main.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 07e8f671..70c53762 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "log" "net" "os" + "os/exec" "path" "runtime" "strconv" @@ -86,17 +87,32 @@ func main() { }(s) if !quiet { - for _, config := range configs { - fmt.Println(config.Address()) - } - + var checkedFdLimit bool for addr, configs := range addresses { 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) { fmt.Printf("Notice: %s is only accessible on this machine (%s)\n", 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 + } + } } } }