Adding the ability to check the system limit on open files (important for watching large sites)

This commit is contained in:
spf13 2014-02-01 12:50:17 -05:00
parent c1b9380dfd
commit ae9cc09b04

View file

@ -14,10 +14,16 @@
package commands
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/hugo/hugolib"
"syscall"
)
func init() {
check.AddCommand(limit)
}
var check = &cobra.Command{
Use: "check",
Short: "Check content in the source directory",
@ -29,3 +35,31 @@ var check = &cobra.Command{
site.Analyze()
},
}
var limit = &cobra.Command{
Use: "ulimit",
Short: "Check system ulimit settings",
Long: `Hugo will inspect the current ulimit settings on the system.
This is primarily to ensure that Hugo can watch enough files on some OSs`,
Run: func(cmd *cobra.Command, args []string) {
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
fmt.Println("Error Getting Rlimit ", err)
}
fmt.Println("Current rLimit:", rLimit)
fmt.Println("Attempting to increase limit")
rLimit.Max = 999999
rLimit.Cur = 999999
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
fmt.Println("Error Setting rLimit ", err)
}
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
fmt.Println("Error Getting rLimit ", err)
}
fmt.Println("rLimit after change:", rLimit)
},
}