Skip to content

Commit 26aa06a

Browse files
committed
Revert "commands: Remove the rlimit tweaking on macOS"
This reverts commit bcd32f1. See #3582
1 parent 52a0cea commit 26aa06a

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

‎commands/hugo.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"net/http"
2626
"os"
2727
"path/filepath"
28+
"runtime"
2829
"strings"
2930
"sync"
3031
"time"
@@ -758,6 +759,10 @@ func (c *commandeer) rebuildSites(events []fsnotify.Event) error {
758759

759760
// newWatcher creates a new watcher to watch filesystem events.
760761
func (c *commandeer) newWatcher(port int) error {
762+
if runtime.GOOS == "darwin" {
763+
tweakLimit()
764+
}
765+
761766
watcher, err := watcher.New(1 * time.Second)
762767
var wg sync.WaitGroup
763768

‎commands/limit_darwin.go‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2015 The Hugo Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
// Copyright 2015 The Hugo Authors. All rights reserved.
15+
//
16+
// Licensed under the Apache License, Version 2.0 (the "License");
17+
// you may not use this file except in compliance with the License.
18+
// You may obtain a copy of the License at
19+
// http://www.apache.org/licenses/LICENSE-2.0
20+
//
21+
// Unless required by applicable law or agreed to in writing, software
22+
// distributed under the License is distributed on an "AS IS" BASIS,
23+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24+
// See the License for the specific language governing permissions and
25+
// limitations under the License.
26+
27+
package commands
28+
29+
import (
30+
"syscall"
31+
32+
"github.com/spf13/cobra"
33+
jww "github.com/spf13/jwalterweatherman"
34+
)
35+
36+
func init() {
37+
checkCmd.AddCommand(limit)
38+
}
39+
40+
var limit = &cobra.Command{
41+
Use: "ulimit",
42+
Short: "Check system ulimit settings",
43+
Long: `Hugo will inspect the current ulimit settings on the system.
44+
This is primarily to ensure that Hugo can watch enough files on some OSs`,
45+
RunE: func(cmd *cobra.Command, args []string) error {
46+
var rLimit syscall.Rlimit
47+
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
48+
if err != nil {
49+
return newSystemError("Error Getting Rlimit ", err)
50+
}
51+
52+
jww.FEEDBACK.Println("Current rLimit:", rLimit)
53+
54+
jww.FEEDBACK.Println("Attempting to increase limit")
55+
rLimit.Max = 999999
56+
rLimit.Cur = 999999
57+
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
58+
if err != nil {
59+
return newSystemError("Error Setting rLimit ", err)
60+
}
61+
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
62+
if err != nil {
63+
return newSystemError("Error Getting rLimit ", err)
64+
}
65+
jww.FEEDBACK.Println("rLimit after change:", rLimit)
66+
67+
return nil
68+
},
69+
}
70+
71+
func tweakLimit() {
72+
var rLimit syscall.Rlimit
73+
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
74+
if err != nil {
75+
jww.ERROR.Println("Unable to obtain rLimit", err)
76+
}
77+
if rLimit.Cur < rLimit.Max {
78+
rLimit.Max = 999999
79+
rLimit.Cur = 999999
80+
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
81+
if err != nil {
82+
jww.ERROR.Println("Unable to increase number of open files limit", err)
83+
}
84+
}
85+
}

‎commands/limit_others.go‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2015 The Hugo Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
// +build !darwin
15+
// Copyright 2015 The Hugo Authors. All rights reserved.
16+
//
17+
// Licensed under the Apache License, Version 2.0 (the "License");
18+
// you may not use this file except in compliance with the License.
19+
// You may obtain a copy of the License at
20+
// http://www.apache.org/licenses/LICENSE-2.0
21+
//
22+
// Unless required by applicable law or agreed to in writing, software
23+
// distributed under the License is distributed on an "AS IS" BASIS,
24+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
// See the License for the specific language governing permissions and
26+
// limitations under the License.
27+
28+
package commands
29+
30+
func tweakLimit() {
31+
// nothing to do
32+
}

0 commit comments

Comments
 (0)