Skip to content

Commit

Permalink
Finished renaming all the spark references to spark2
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Nov 4, 2010
1 parent cc441f1 commit 1f5b59a
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 49 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG

This file was deleted.

20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2010 Sencha Inc.

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.

73 changes: 40 additions & 33 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
# Spark
# Spark2

Spark is a command-line tool used to start up node server instances written by [Tj Holowaychuk](http://github.com/visionmedia) and [Tim Caswell](http://github.com/creationix). It's part of the [Connect](http://github.com/senchalabs/connect) framework, however can be used standalone with _any_ node server.
Spark2 is a fork of the Spark command-line tool used to start up node server instances written by [Tj Holowaychuk](http://github.com/visionmedia) and [Tim Caswell](http://github.com/creationix). It's part of the [Connect](http://github.com/senchalabs/connect) framework, however can be used standalone with _any_ node server.

## Why the fork?

Due to the nature of the CLA required to submit my changes back to Sencha, I have chosen to fork Spark myself and add the features I needed.

## What is different?

For the most part, they are identical. Spark2 contains some helpful management tools missing from the original.

The most useful is the "auto re-spawn children" feature. If a worker dies, spark2 will respawn a replacement child.

You can also manage the server for hot code deployment. The original Spark had the main process listen on the app as well as the workers. Spark2's main process doesn't listen on the app, only the workers do.
That allows you to do things like this:

spark2 -n 10 &
--exit the terminal and log back in..
--Now update your source, then
spark2 --respawn (This will respawn all the worker processes to reload the code.

You can also call:
spark2 --kill to kill the main process and it's workers.

This can also be done from the shell by sending the right signals:

kill -s SIGCONT PID (respawn all children)
kill PID (kill)

I also fixed an issue where command line arguments are overwritten if there is a config. Now commandline arguments override the config so you can test locally with a production config.

## Features

Spark provides the following options when starting a server.
Spark2 provides the following options when starting a server.

- Port/Host to listen on
- SSL hosting with specified key/certificate
Expand All @@ -19,7 +47,7 @@ Spark provides the following options when starting a server.

## Making an app spark compatible

Any node server can be used with spark. All you need to do it create a file called `app.js` that exports the instance of `http.Server` or `net.Server`.
Any node server can be used with spark2. All you need to do it create a file called `app.js` that exports the instance of `http.Server` or `net.Server`.

A hello-world example would look like this:

Expand All @@ -28,43 +56,22 @@ A hello-world example would look like this:
res.end("Hello World");
});

And then to run it you simply go to the folder containing the `app.js` and type:
And then to run it you simply go to the folder containing the `app.js` or `server.js` and type:

$ spark
$ spark2

The output you'll see will be:

Spark server(34037) listening on http://*:3000 in development mode
Spark2 server(34037) listening on http://*:3000 in development mode

Where `34037` is the process id. If you want 4 processes to balance the requests across, no problem.

$ spark -n 4
$ spark2 -n 4

And you'll see:

Spark server(34049) listening on http://*:3000 in development mode
Spark server(34050) listening on http://*:3000 in development mode
Spark server(34052) listening on http://*:3000 in development mode
Spark server(34051) listening on http://*:3000 in development mode

## MIT License

Copyright (c) 2010 Sencha Inc.

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.
Spark2 server(34049) listening on http://*:3000 in development mode
Spark2 server(34050) listening on http://*:3000 in development mode
Spark2 server(34052) listening on http://*:3000 in development mode
Spark2 server(34051) listening on http://*:3000 in development mode

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.
19 changes: 13 additions & 6 deletions bin/spark → bin/spark2
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var verbose;
var respawn;
var kill;
var force;
var spawn;

/**
* Colored terminal output.
Expand All @@ -69,7 +70,7 @@ var env = process.sparkEnv = {
*/

var usage = ''
+ '[bold]{Usage}: spark [options]\n'
+ '[bold]{Usage}: spark2 [options]\n'
+ '\n'
+ '[bold]{Options}:\n'
+ ' --comment Ignored, this is to label the process in htop\n'
Expand All @@ -87,10 +88,13 @@ var usage = ''
+ ' -u, --user ID|NAME Change user with setuid()\n'
+ ' -g, --group ID|NAME Change group with setgid()\n'
+ ' -v, --verbose Enable verbose output\n'
+ ' -V, --version Output spark version\n'
+ ' -V, --version Output spark2 version\n'
+ ' -K, --no-color Suppress colored terminal output\n'
+ ' -h, --help Outputy help information\n'
+ ' --ENV VAL Sets the given spark environment variable\n'
+ ' --ENV VAL Sets the given spark2 environment variable\n'
+ ' --kill Kill the currently running server\n'
+ ' --respawn Restart all workers on the currently running server\n'
+ ' --force Kill the lock file on the current server and start\n'
;

/**
Expand Down Expand Up @@ -271,7 +275,7 @@ function startWorker() {
});
stdin.addListener('fd', function(fd){
var app = requireApp(getAppPath());
util.error('Spark server(' + process.pid + ') listening on '
util.error('Spark2 server(' + process.pid + ') listening on '
+ 'http' + (env.sslKey ? 's' : '') + '://'
+ (env.host || '*') + ':' + env.port
+ ' in ' + env.name + ' mode');
Expand Down Expand Up @@ -332,7 +336,7 @@ var respawnAll = function() {

var getTmpFile = function(path) {
path = path.replace(/\//g, '-').replace(/ /g, '');
var file = process.env.TMPDIR + 'spark-' + path;
var file = process.env.TMPDIR + 'spark2-' + path;
return file;
}

Expand Down Expand Up @@ -361,6 +365,10 @@ function start() {
loadConfig('./config.js');
}

if (!workers) {
abort('Must have at least one worker..');
}

// Application path
var path = getAppPath();

Expand Down Expand Up @@ -388,7 +396,6 @@ function start() {
return;
}
}

writePid(path);

// Spawn worker processes
Expand Down
6 changes: 3 additions & 3 deletions examples/config/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
var http = require('http');

/**
* `$ spark --chdir examples/config`
* `$ spark2 --chdir examples/config`
* will auto-detect ./config.js and apply it.
*
* `$ spark --config path/to/config examples/config.app`
* `$ spark2 --config path/to/config examples/config.app`
* will load the app relative to CWD, and the given config module.
*
* NOTE: you can use --config several times to apply different configurations
Expand All @@ -21,4 +21,4 @@ module.exports = http.createServer(function(req, res){
'Content-Type': 'text/plain'
});
res.end('Wahoo');
});
});
2 changes: 1 addition & 1 deletion examples/custom-config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ sys.log('loading config file "config/' + process.sparkEnv.name + '.js"');
module.exports = http.createServer(function(req, res, next){
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end(sys.inspect(process.sparkEnv));
});
});
2 changes: 1 addition & 1 deletion examples/ssl/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# Demonstrates usage of SSL support in the executable(1) binary.
#

../../bin/spark --ssl-key privatekey.pem --ssl-crt certificate.pem
../../bin/spark2 --ssl-key privatekey.pem --ssl-crt certificate.pem
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
"name": "spark2",
"description": "Powerful node server starter - Fork of the original",
"version": "2.0.0",
"author": "Dav Glass <davglass@gmail.com>",
"bugs": { "web" : "http://github.com/davglass/spark/issues" },
"contributors": [
{ "name": "Dav Glass", "email": "davglass@gmail.com" },
{ "name": "Tim Caswell", "email": "tim@sencha.com" },
{ "name": "TJ Holowaychuk", "email": "tj@sencha.com" }
],
"bin": { "spark2": "./bin/spark" },
"engines": { "node": ">= 0.1.199" }
"bin": { "spark2": "./bin/spark2" },
"engines": { "node": ">= 0.1.199" },
"licenses":[
{
"type" : "MIT",
"url" : "http://github.com/davglass/blob/master/LICENSE"
}
],
"repository": {
"type":"git",
"url":"http://github.com/davglass/spark.git"
}
}

0 comments on commit 1f5b59a

Please sign in to comment.