Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds exit callbacks, scpOptions, config task command line arguments r…
…ewriting, and example controller script demonstrating usage of the new features.
- Loading branch information
Showing
5 changed files
with
170 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*global require, process, console */ | ||
|
||
// Example with some advanced usage, like error callbacks, scpOptions, | ||
// and config task command line arguments rewriting, using localhost as | ||
// a 'remote' machine. | ||
|
||
var control = require('../'), | ||
task = control.task, | ||
script = process.argv[1], | ||
scpTest = 'controlScpTest'; | ||
|
||
function configure(addresses) { | ||
var config; | ||
config = { | ||
user: process.env.USER, | ||
scpOptions: ['-v'] | ||
}; | ||
return control.hosts(config, addresses); | ||
} | ||
|
||
task('mycluster', 'Config for my cluster', function () { | ||
return configure([ 'localhost' ]); // Expand array to create cluster | ||
}); | ||
|
||
task('myhost', 'Config for a single host from command line', function (args) { | ||
return configure([args.shift()]); // From command line arguments rewriting | ||
}); | ||
|
||
function doTest(host, code, callback, exitCallback) { | ||
code = code || 0; | ||
host.ssh('node ' + script + ' mycluster arbexit ' + code, | ||
callback, exitCallback); | ||
} | ||
|
||
// Task to perform 'remote' call requesting 'remote' to exit arbitrarily | ||
task('test', 'Test task', function (host, code) { | ||
|
||
function callback() { | ||
console.log('Regular callback activated for ' + host.address); | ||
} | ||
|
||
function exitCallback(exit) { | ||
console.log('Exit callback activated for ' + host.address + | ||
' with exit code ' + exit); | ||
} | ||
|
||
doTest(host, code, callback, exitCallback); | ||
}); | ||
|
||
// Task that will run on 'remote' to exit with an arbitrary code | ||
task('arbexit', 'Arbitrary exit', function (host, code) { | ||
code = code || 0; | ||
console.log("Exiting with code " + code); | ||
process.exit(code); | ||
}); | ||
|
||
task('scp', 'Test scp options', function (host) { | ||
host.scp(script, scpTest); | ||
}); | ||
|
||
task('clean', 'Remove file transferred in scp testing', function (host) { | ||
host.ssh('rm ' + scpTest); | ||
}); | ||
|
||
control.begin(); | ||
|
||
// Run like: | ||
// node mycontroller.js mycluster test 0 | ||
// node mycontroller.js mycluster test 64 | ||
// node mycontroller.js mycluster scp | ||
// node mycontroller.js mycluster clean | ||
// node mycontroller.js myhost 127.0.0.1 test 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters