Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
5db8b166
Commit
5db8b166
authored
Apr 07, 2016
by
Jeromy Johnson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2466 from ipfs/feat/fd-limit-check
try to raise ulimit if its too low
parents
ae3fed72
e6618325
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
3 deletions
+58
-3
cmd/ipfs/daemon.go
cmd/ipfs/daemon.go
+11
-0
cmd/ipfs/ulimit_unix.go
cmd/ipfs/ulimit_unix.go
+47
-0
test/sharness/t0061-daemon-opts.sh
test/sharness/t0061-daemon-opts.sh
+0
-3
No files found.
cmd/ipfs/daemon.go
View file @
5db8b166
...
...
@@ -40,6 +40,7 @@ const (
unrestrictedApiAccessKwd
=
"unrestricted-api"
unencryptTransportKwd
=
"disable-transport-encryption"
enableGCKwd
=
"enable-gc"
adjustFDLimitKwd
=
"manage-fdlimit"
// apiAddrKwd = "address-api"
// swarmAddrKwd = "address-swarm"
)
...
...
@@ -132,6 +133,7 @@ future version, along with this notice. Please move to setting the HTTP Headers.
cmds
.
BoolOption
(
unrestrictedApiAccessKwd
,
"Allow API access to unlisted hashes"
),
cmds
.
BoolOption
(
unencryptTransportKwd
,
"Disable transport encryption (for debugging protocols)"
),
cmds
.
BoolOption
(
enableGCKwd
,
"Enable automatic periodic repo garbage collection"
),
cmds
.
BoolOption
(
adjustFDLimitKwd
,
"Check and raise file descriptor limits if needed"
),
// TODO: add way to override addresses. tricky part: updating the config if also --init.
// cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
...
...
@@ -152,10 +154,19 @@ func defaultMux(path string) corehttp.ServeOption {
}
}
var
fileDescriptorCheck
=
func
()
error
{
return
nil
}
func
daemonFunc
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
// let the user know we're going.
fmt
.
Printf
(
"Initializing daemon...
\n
"
)
managefd
,
_
,
_
:=
req
.
Option
(
adjustFDLimitKwd
)
.
Bool
()
if
managefd
{
if
err
:=
fileDescriptorCheck
();
err
!=
nil
{
log
.
Error
(
"setting file descriptor limit: %s"
,
err
)
}
}
ctx
:=
req
.
InvocContext
()
go
func
()
{
...
...
cmd/ipfs/ulimit_unix.go
0 → 100644
View file @
5db8b166
// +build linux darwin
package
main
import
(
"fmt"
"os"
"strconv"
"syscall"
)
var
ipfsFileDescNum
=
uint64
(
2048
)
func
init
()
{
if
val
:=
os
.
Getenv
(
"IPFS_FD_MAX"
);
val
!=
""
{
n
,
err
:=
strconv
.
Atoi
(
val
)
if
err
!=
nil
{
log
.
Error
(
"bad value for IPFS_FD_MAX: %s"
,
err
)
}
else
{
ipfsFileDescNum
=
uint64
(
n
)
}
}
fileDescriptorCheck
=
checkAndSetUlimit
}
func
checkAndSetUlimit
()
error
{
var
rLimit
syscall
.
Rlimit
err
:=
syscall
.
Getrlimit
(
syscall
.
RLIMIT_NOFILE
,
&
rLimit
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error getting rlimit: %s"
,
err
)
}
if
rLimit
.
Cur
<
ipfsFileDescNum
{
if
rLimit
.
Max
<
ipfsFileDescNum
{
rLimit
.
Max
=
ipfsFileDescNum
}
fmt
.
Printf
(
"Adjusting current ulimit to %d.
\n
"
,
ipfsFileDescNum
)
rLimit
.
Cur
=
ipfsFileDescNum
}
err
=
syscall
.
Setrlimit
(
syscall
.
RLIMIT_NOFILE
,
&
rLimit
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error setting ulimit: %s"
,
err
)
}
return
nil
}
test/sharness/t0061-daemon-opts.sh
View file @
5db8b166
...
...
@@ -13,9 +13,6 @@ test_init_ipfs
test_launch_ipfs_daemon
--unrestricted-api
--disable-transport-encryption
test_expect_success
"convert addresses from multiaddrs"
'
'
gwyaddr
=
$GWAY_ADDR
apiaddr
=
$API_ADDR
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment