NOTE: up has been renamed in npm as "up-time" https://npmjs.org/package/up-time
Zero-downtime reloads built on top of the distribute load balancer.
Simply running
$ up --port 80 --watch my-http-server.js
Will start my-http-server.js
on port 80, then reload it with no downtime
when files change in the working directory.
This project is deprecated!
Keep-Alive
sockets while reloading.Make sure you structure your code so that your http
server lives in a
separate module that can be require
d.
server.js
module.exports = http.Server(function (req, res) {
res.writeHead(200);
res.end('Hello World');
});
To get the up
command, make sure to install with the -g
flag:
$ npm install -g up
Usage: up [options]
The up
command accepts the following options:
-p
/--port
listen
s.3000
.-w
/--watch
-r
/--require
<mod>
--require|-r coffee-script
-n
/--number
cpus
variable. eg: cpus + 2
.Math
methods. eg: round(cpus / 2)
.1
if NODE_ENV
is development
.-t
/--timeout
'10s'
are accepted.'10m'
, or '500ms'
if NODE_ENV
is development
.-k
/--keepalive
-f
/--pidfile
cat pidfile.txt
"-T
/--title
process.title
.up
.master
or worker
(e.g "up master", "up worker").var up = require('up')
, master = http.Server().listen(3000)
// initialize up
var srv = up(master, __dirname + '/server');
process.on('SIGUSR2', function () {
srv.reload();
});
require('up')
exports the UpServer
constructor, which takes three
parameters:
http.Server
) server to accept connections onString
) absolute path to the module.Object
)
numWorkers
: (Number
|String
): see --workers
above.workerTimeout
: (Number
|String
): see --timeout
above.title
: (String
): see --title
above.assumeReady
: (Boolean
): see Worker readiness below.keepAlive
: (Boolean
): see --keepalive
above.minExpectedLifetime
: (Number
|String
): Number of ms a worker is
expected to live. Don't auto-respawn if a worker dies earlier. Strings
like '10s'
are accepted. Defaults to '20s'
.An UpServer
inherits from a Distributor
, which means you can use()
any distribute middleware.
The main difference is that the "default handler" of up (ie: the last function in the middleware chain) is the one that executes the round-robin load balancing.
To reload the workers, call srv.reload()
. In the example above and CLI,
this is called by sending the SIGUSR2
signal:
$ kill -s SIGUSR2 <process id>
If you're running with up
CLI, this command is output to stderr for your
convenience.
The CLI tool also auto-reloads if you pass the --watch
option and a file
changes in the working directory.
workerTimeout
, which defaults to 10
minutes in production. This means that if a user was uploading a file, his
request will be processed without interruptions.By default up assume that new workers are ready for new connections,
immediately after they have been required. This can be changed by setting
assumeReady
to false
, on the options
object when initializing
the up server through the JavaScript API.
The worker then needs to tell up, when it's ready, like this:
var up = require('up');
// Dummy async event
setTimeout(function(){
up.ready();
}, 1000);
(The MIT License)
Copyright (c) 2011 Guillermo Rauch <guillermo@learnboost.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.