diff --git a/package.json b/package.json index cee83df..eba7184 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "md5": "^2.2.1", "mkdirp": "^0.5.1", "pm2": "^2.3.0", + "portscanner": "^2.1.1", "ps-node": "^0.1.4", "request": "^2.80.0", "rimraf": "^2.6.1", diff --git a/routes/ports.js b/routes/ports.js new file mode 100644 index 0000000..c5924e9 --- /dev/null +++ b/routes/ports.js @@ -0,0 +1,52 @@ +const assetChainPorts = { + 'komodod': '7771', + 'SUPERNET': '11341', + 'REVS': '10196', + 'WLC': '11667', + 'PANGEA': '10074', + 'DEX': '9503', + 'JUMBLR': '10789', + 'BET': '11222', + 'CRYPTO': '10420', + 'HODL': '8010', + 'SHARK': '14104', + 'BOTS': '10151', + 'MGW': '15524', + 'MVP': '11676', + 'KV': '9747', + 'CEAL': '13097', + 'MESH': '8400', + 'USD': '13967', + 'CHF': '15312', + 'CAD': '8720', + 'BRL': '9914', + 'BGN': '9110', + 'AUD': '8045', + 'PLN': '13493', + 'PHP': '11181', + 'NZD': '10915', + 'NOK': '11588', + 'MYR': '10688', + 'MXN': '13970', + 'KRW': '14020', + 'JPY': '13145', + 'INR': '10536', + 'ILS': '14638', + 'IDR': '14459', + 'HKD': '15409', + 'HUF': '13699', + 'GBP': '11505', + 'EUR': '8065', + 'DKK': '13830', + 'CNY': '10384', + 'ZAR': '15160', + 'TRY': '13924', + 'THB': '11847', + 'SGD': '14475', + 'SEK': '11447', + 'RON': '8675', + 'RUB': '8199', + 'CZK': '9482' +}; + +module.exports = assetChainPorts; \ No newline at end of file diff --git a/routes/shepherd.js b/routes/shepherd.js index 931a25a..acf4803 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -15,7 +15,8 @@ const electron = require('electron'), pm2 = require('pm2'), request = require('request'), async = require('async'), - rimraf = require('rimraf'); + rimraf = require('rimraf'), + portscanner = require('portscanner'); Promise = require('bluebird'); @@ -23,6 +24,7 @@ const fixPath = require('fix-path'); var ps = require('ps-node'), setconf = require('../private/setconf.js'), kmdcli = require('../private/kmdcli.js'), + assetChainPorts = require('./ports.js') shepherd = express.Router(); // IGUANA FILES AND CONFIG SETTINGS @@ -650,26 +652,35 @@ function herder(flock, data) { console.log('komodod debug.log access err: ' + e); } + // get komodod instance port + var _port = assetChainPorts[data.ac_name]; + try { - pm2.connect(true, function(err) { // start up pm2 god - if (err) { - console.error(err); - process.exit(2); - } + // check if komodod instance is already running + portscanner.checkPortStatus(_port, '127.0.0.1', function(error, status) { + // Status is 'open' if currently in use or 'closed' if available + if (status === 'closed') { + pm2.connect(true, function(err) { // start up pm2 god + if (err) { + console.error(err); + process.exit(2); + } - data.ac_options.push('-reindex &'); - - pm2.start({ - script: komododBin, // path to binary - name: data.ac_name, // REVS, USD, EUR etc. - exec_mode : 'fork', - cwd: komodoDir, - args: data.ac_options - }, function(err, apps) { - pm2.disconnect(); // Disconnect from PM2 - if (err) - throw err; - }); + pm2.start({ + script: komododBin, // path to binary + name: data.ac_name, // REVS, USD, EUR etc. + exec_mode : 'fork', + cwd: komodoDir, + args: data.ac_options + }, function(err, apps) { + pm2.disconnect(); // Disconnect from PM2 + if (err) + throw err; + }); + }); + } else { + console.log('port ' + _port + ' (' + data.ac_name + ') is already in use'); + } }); } catch(e) { console.log('failed to start komodod err: ' + e);