Behind the scenes: GridControl is a network layer built on top of PM2 allowing file synchronization, inter-process communication via an opionated PUB/SUB system and a wide-range system discovery
Change each attribute to the desired value.
Note that an SSH client should be running on the defaut port (22) on each remote machine
2/ Provision every host listed in the Gridfile:
$ grid provision
This will copy the SSH pub key and install NVM, Node.js, PM2 and GridcontrolThis installation does not need ROOT access rights at any time
3/ Grid management
$ grid dash
Commands to manage your grid:
# List all nodes linked to the grid$ grid ls# Display Dashboard$ grid dash# Execute a command on each server$ grid multissh <bash_command># Restart/Recover the current Grid$ grid restart# Upgrade Gridcontrol to latest version$ grid upgrade# Display realtime logs of all tasks$ grid logs# Monitor the whole Grid with Keymetrics$ grid monitor <secret> <public>$ grid unmonitor# Interactively SSH into desired machine
Interact with the Grid
Now let's play with the Grid.
You can generate a sample project by typing:
$ grid sample [project-name]$ cd [project-name]$ npm install
Let's look at the content of tasks/get-ip.js, this is a task that will be propagated in the grid:
var request = require('request');module.exports = function(context, cb) { request('https://api.ipify.org/?format=json', function (error, response, body) { if (error) return cb(error); if (!error && response.statusCode == 200) { return cb(null, body); } });};
To call this function, look at how it's done in index.js:
var grid = require('grid-api').init({ instances : 1, env : { NODE_ENV : 'development' }});function triggerTask() { // 'get-ip' is the filename grid.exec('get-ip', function(err, data, server) { if (err) { console.log(err); return false; } console.log('Got response from server pub_ip=(%s) priv_ip=(%s):', server.public_ip, server.private_ip); console.log(data); });
Start the main application:
$ node index.js
At the beginning, only the local gridcontrol will respond. Once the other peers are synchronized they will also process the queries:
Got response from server pub_ip=(88.123.12.21) priv_ip=(10.2.2.1):$HTMLGot response from server pub_ip=(88.123.12.22) priv_ip=(10.2.2.8):$HTMLGot response from server pub_ip=(88.125.120.20) priv_ip=(10.2.2.10):$HTMLGot response from server pub_ip=(88.123.23.42) priv_ip=(10.2.2.12):$HTML