Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.12.10

* Ensure that config_reader.read() runs after config_seeder.set() [GH-69]

v0.12.9

* Use `global.token` on config_reader.js [GH-67]
Expand Down
3 changes: 2 additions & 1 deletion lib/config_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ exports.read = function(params, cb) {
}

if (global.token) {
params = _.extend(params, {'token': global.token})
params = _.extend(params, {'token': global.token});
}

consul.kv.get(params, function(err, item) {
if (err) return cb(err);

Expand Down
110 changes: 57 additions & 53 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ for (var i=2; i<process.argv.length; ++i) {

if(process.argv[i] === '-f' || process.argv[i] === '--config-file') {
if(i+1 >= process.argv.length) {
logger.error("No token provided with --config-file option");
logger.error("No file provided with --config-file option");
process.exit(7);
}
global.config_file = process.argv[i+1];
Expand All @@ -65,74 +65,78 @@ for (var i=2; i<process.argv.length; ++i) {
var config_reader = require('./config_reader.js');
var config_seeder = require('./config_seeder.js');

if (global.config_file) {
config_seeder.set(global.config_key, global.config_file, function(err) {
if (err) {
logger.error(err)
process.exit(2)
};
});
}

/**
* Read config from a specially named Consul resource. If the config was not seeded
* (and this should be done using utils/config_seeder.js), git2consul will not boot.
*/
config_reader.read({'key': global.config_key}, function(err, config) {
var read_config = function(){
config_reader.read({'key': global.config_key}, function(err, config) {

if (err) return console.error(err);
if (err) return console.error(err);

// Logging configuration is specified in the config object, so initialize our logger
// around that config.
logger.init(config);
// Logging configuration is specified in the config object, so initialize our logger
// around that config.
logger.init(config);

if (global.token) {
// If a token was configured, register it with the consul broker
require('./consul').setToken(global.token);
}
if (global.token) {
// If a token was configured, register it with the consul broker
require('./consul').setToken(global.token);
}

var git = require('./git');
var git = require('./git');

if (!config.repos || !config.repos.length > 0) {
// Fail startup.
logger.error("No repos found in configuration. Halting.")
process.exit(1);
}
if (!config.repos || !config.repos.length > 0) {
// Fail startup.
logger.error("No repos found in configuration. Halting.")
process.exit(1);
}

// Process command line switches, if any. Command-line switches override the settings
// loaded from Consul.
for (var i=2; i<process.argv.length; ++i) {
if (process.argv[i] === '-n' || process.argv[i] === '--no_daemon') config['no_daemon'] = true;
if (process.argv[i] === '-h' || process.argv[i] === '--halt_on_change') config['halt_on_change'] = true;
else if (process.argv[i] === '-d' || process.argv[i] === '--local_store') {
if (i+1 >= process.argv[length]) {
logger.error("No dir provided with --local_store option");
process.exit(3);
// Process command line switches, if any. Command-line switches override the settings
// loaded from Consul.
for (var i=2; i<process.argv.length; ++i) {
if (process.argv[i] === '-n' || process.argv[i] === '--no_daemon') config['no_daemon'] = true;
if (process.argv[i] === '-h' || process.argv[i] === '--halt_on_change') config['halt_on_change'] = true;
else if (process.argv[i] === '-d' || process.argv[i] === '--local_store') {
if (i+1 >= process.argv[length]) {
logger.error("No dir provided with --local_store option");
process.exit(3);
}
config['local_store'] = process.argv[i+1];
++i;
}
config['local_store'] = process.argv[i+1];
++i;
}
}

if (!config.local_store) {
config.local_store = os.tmpdir();
}
if (!config.local_store) {
config.local_store = os.tmpdir();
}

logger.info('git2consul is running');

logger.info('git2consul is running');
process.on('uncaughtException', function(err) {
logger.error("Uncaught exception " + err);
});

process.on('uncaughtException', function(err) {
logger.error("Uncaught exception " + err);
// Set up git for each repo
git.createRepos(config, function(err) {
if (err) {
logger.error('Failed to create repos due to %s', err);
setTimeout(function() {
// If any git manager failed to start, consider this a fatal error.
process.exit(2);
}, 2000);
}
});
});
};

// Set up git for each repo
git.createRepos(config, function(err) {
if (global.config_file) {
config_seeder.set(global.config_key, global.config_file, function(err) {
if (err) {
logger.error('Failed to create repos due to %s', err);
setTimeout(function() {
// If any git manager failed to start, consider this a fatal error.
process.exit(2);
}, 2000);
}
logger.error(err)
process.exit(2)
};
read_config();
});

});
} else {
read_config();
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "git2consul",
"description": "System for moving data from git to consul",
"license": "Apache-2.0",
"version": "0.12.9",
"version": "0.12.10",
"contributors": [
{
"name": "Ryan Breen",
Expand Down