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:
parent
5e8491cf7f
commit
26bb17337e
1 changed files with 20 additions and 4 deletions
24
main.go
24
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue