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"
"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
}
}
}
}
}