├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── package.json └── test └── basic.js /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: true 3 | node_js: 4 | - lts/* 5 | env: 6 | - CXX=g++-4.8 7 | addons: 8 | apt: 9 | sources: 10 | - ubuntu-toolchain-r-test 11 | packages: 12 | - g++-4.8 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Feross Aboukhadijeh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # unlimited [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] 2 | 3 | [travis-image]: https://img.shields.io/travis/feross/unlimited/master.svg 4 | [travis-url]: https://travis-ci.org/feross/unlimited 5 | [npm-image]: https://img.shields.io/npm/v/unlimited.svg 6 | [npm-url]: https://npmjs.org/package/unlimited 7 | [downloads-image]: https://img.shields.io/npm/dm/unlimited.svg 8 | [downloads-url]: https://npmjs.org/package/unlimited 9 | [standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg 10 | [standard-url]: https://standardjs.com 11 | 12 | ### Upgrade the maximum file descriptor number (`'nofile'`) that can be opened by this process 13 | 14 | ## install 15 | 16 | ``` 17 | npm install unlimited 18 | ``` 19 | 20 | ## usage 21 | 22 | To attempt to upgrade the maximum file descriptor number that can be opened by this process 23 | to effectively unlimited (`65536`): 24 | 25 | ```js 26 | var unlimited = require('unlimited') 27 | unlimited() 28 | ``` 29 | 30 | Or specify a specific `'nofile'` number to use: 31 | 32 | ```js 33 | unlimited(10000) 34 | ``` 35 | 36 | If the current user's permissions or the system's `'hard'` limit do not allow the maximum 37 | file descriptor number to be increased, this function will do nothing (no-op). 38 | 39 | For best results, start your node process as `root`, run `unlimited()`, then downgrade 40 | the user permissions with the [`downgrade`](https://github.com/feross/downgrade) package. 41 | 42 | On non-posix platforms (e.g. Windows), this module does nothing. 43 | 44 | ## license 45 | 46 | MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org). 47 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! unlimited. MIT License. Feross Aboukhadijeh */ 2 | var debug = require('debug')('unlimited') 3 | var posix 4 | try { posix = require('posix') } catch (err) {} 5 | 6 | var DEFAULT_LIMIT = 65536 7 | 8 | module.exports = function unlimited (limit) { 9 | if (!limit) limit = DEFAULT_LIMIT 10 | if (!posix) { 11 | debug('Failed to upgrade resource limits - missing `posix` package') 12 | return 13 | } 14 | try { 15 | posix.setrlimit('nofile', { 16 | soft: limit, 17 | hard: limit 18 | }) 19 | debug('Upgraded resource limits to ' + posix.getrlimit('nofile').soft) 20 | } catch (err) { 21 | debug('Failed to upgrade resource limits: %s', err.message || err) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unlimited", 3 | "description": "Upgrade the maximum file descriptor number (`'nofile'`) that can be opened by this process", 4 | "version": "1.2.2", 5 | "author": { 6 | "name": "Feross Aboukhadijeh", 7 | "email": "feross@feross.org", 8 | "url": "https://feross.org" 9 | }, 10 | "bugs": { 11 | "url": "https://github.com/feross/unlimited/issues" 12 | }, 13 | "dependencies": { 14 | "debug": "^4.1.1" 15 | }, 16 | "devDependencies": { 17 | "standard": "*", 18 | "tape": "^5.0.1" 19 | }, 20 | "homepage": "https://github.com/feross/unlimited", 21 | "keywords": [ 22 | "upgrade ulimit", 23 | "ulimit", 24 | "posix", 25 | "unlimited ulimit", 26 | "unlimited rlimit", 27 | "rlimit", 28 | "set rlimit", 29 | "setrlimit", 30 | "set ulimit", 31 | "setulimit", 32 | "server", 33 | "nofile", 34 | "unlimited nofile", 35 | "unlimited", 36 | "posix.setrlimit" 37 | ], 38 | "license": "MIT", 39 | "main": "index.js", 40 | "repository": { 41 | "type": "git", 42 | "url": "git://github.com/feross/unlimited.git" 43 | }, 44 | "scripts": { 45 | "test": "standard && tape test/*.js" 46 | }, 47 | "optionalDependencies": { 48 | "posix": "^4.2.0" 49 | }, 50 | "funding": [ 51 | { 52 | "type": "github", 53 | "url": "https://github.com/sponsors/feross" 54 | }, 55 | { 56 | "type": "patreon", 57 | "url": "https://www.patreon.com/feross" 58 | }, 59 | { 60 | "type": "consulting", 61 | "url": "https://feross.org/support" 62 | } 63 | ] 64 | } 65 | -------------------------------------------------------------------------------- /test/basic.js: -------------------------------------------------------------------------------- 1 | var posix = require('posix') 2 | var test = require('tape') 3 | var unlimited = require('../') 4 | 5 | test('basic usage', function (t) { 6 | var hard = posix.getrlimit('nofile').hard 7 | t.doesNotThrow(function () { 8 | unlimited() 9 | }) 10 | t.ok(posix.getrlimit('nofile').soft >= hard) 11 | t.end() 12 | }) 13 | 14 | test('set custom limit', function (t) { 15 | t.doesNotThrow(function () { 16 | unlimited(1000) 17 | }) 18 | t.equal(posix.getrlimit('nofile').soft, 1000) 19 | t.end() 20 | }) 21 | --------------------------------------------------------------------------------