diff --git a/blockchains/supervisor.conf b/blockchains/supervisor.conf index 566fa4dc..c3314227 100644 --- a/blockchains/supervisor.conf +++ b/blockchains/supervisor.conf @@ -1,5 +1,5 @@ [program:${blockchain}] -command=/usr/local/bin/${blockchain_cmd} -datadir=/mnt/blockchain/${blockchain} +command=nice -n +6 /usr/local/bin/${blockchain_cmd} -datadir=/mnt/blockchain/${blockchain} autostart=true autorestart=true stderr_logfile=/var/log/supervisor/${blockchain}.err.log diff --git a/lib/blockchain/common.js b/lib/blockchain/common.js index 7c646dd2..cfd8acfb 100644 --- a/lib/blockchain/common.js +++ b/lib/blockchain/common.js @@ -5,7 +5,15 @@ const cp = require('child_process') const fs = require('fs') const logger = require('console-log-level')({level: 'info'}) -module.exports = {es, writeSupervisorConfig, firewall, randomPass, fetchAndInstall, logger} +module.exports = { + es, + writeSupervisorConfig, + firewall, + randomPass, + fetchAndInstall, + logger, + isInstalledSoftware +} const BINARIES = { BTC: { @@ -49,6 +57,8 @@ function es (cmd) { } function writeSupervisorConfig (coinRec, cmd) { + if (isInstalledSoftware(coinRec)) return + const blockchain = coinRec.code const supervisorConfig = `[program:${blockchain}] @@ -63,9 +73,15 @@ environment=HOME="/root" fs.writeFileSync(`/etc/supervisor/conf.d/${coinRec.code}.conf`, supervisorConfig) } -function fetchAndInstall (crypto) { - const binaries = BINARIES[crypto.cryptoCode] - if (!binaries) throw new Error(`No such coin: ${crypto.code}`) +function isInstalledSoftware (coinRec) { + return fs.existsSync(`/etc/supervisor/conf.d/${coinRec.code}.conf`) +} + +function fetchAndInstall (coinRec) { + if (isInstalledSoftware(coinRec)) return + + const binaries = BINARIES[coinRec.coinRecCode] + if (!binaries) throw new Error(`No such coin: ${coinRec.code}`) const url = binaries.url const downloadFile = path.basename(url) diff --git a/lib/blockchain/install.js b/lib/blockchain/install.js index 9f851260..f824e0c6 100644 --- a/lib/blockchain/install.js +++ b/lib/blockchain/install.js @@ -25,12 +25,16 @@ const PLUGINS = { module.exports = {run} -function installedFilePath (crypto) { +function installedVolumeFilePath (crypto) { return path.resolve(coinUtils.cryptoDir(crypto), '.installed') } -function isInstalled (crypto) { - return fs.existsSync(installedFilePath(crypto)) +function isInstalledVolume (crypto) { + return fs.existsSync(installedVolumeFilePath(crypto)) +} + +function isInstalledSoftware (crypto) { + return common.isInstalledSoftware(crypto) } function processCryptos (codes) { @@ -67,7 +71,7 @@ function setupCrypto (crypto) { common.es('rm -rf *') common.fetchAndInstall(crypto) cryptoPlugin.setup(cryptoDir) - fs.writeFileSync(installedFilePath(crypto), '') + fs.writeFileSync(installedVolumeFilePath(crypto), '') process.chdir(oldDir) } @@ -79,7 +83,7 @@ function plugin (crypto) { function run () { const choices = _.map(c => { - const checked = isInstalled(c) + const checked = isInstalledSoftware(c) && isInstalledVolume() return { name: c.display, value: c.code,