update blockchain install

This commit is contained in:
Josh Harvey 2017-07-12 15:07:13 +03:00
parent 4affb11ba2
commit 8b7a391b41
3 changed files with 30 additions and 10 deletions

View file

@ -1,5 +1,5 @@
[program:${blockchain}] [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 autostart=true
autorestart=true autorestart=true
stderr_logfile=/var/log/supervisor/${blockchain}.err.log stderr_logfile=/var/log/supervisor/${blockchain}.err.log

View file

@ -5,7 +5,15 @@ const cp = require('child_process')
const fs = require('fs') const fs = require('fs')
const logger = require('console-log-level')({level: 'info'}) 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 = { const BINARIES = {
BTC: { BTC: {
@ -49,6 +57,8 @@ function es (cmd) {
} }
function writeSupervisorConfig (coinRec, cmd) { function writeSupervisorConfig (coinRec, cmd) {
if (isInstalledSoftware(coinRec)) return
const blockchain = coinRec.code const blockchain = coinRec.code
const supervisorConfig = `[program:${blockchain}] const supervisorConfig = `[program:${blockchain}]
@ -63,9 +73,15 @@ environment=HOME="/root"
fs.writeFileSync(`/etc/supervisor/conf.d/${coinRec.code}.conf`, supervisorConfig) fs.writeFileSync(`/etc/supervisor/conf.d/${coinRec.code}.conf`, supervisorConfig)
} }
function fetchAndInstall (crypto) { function isInstalledSoftware (coinRec) {
const binaries = BINARIES[crypto.cryptoCode] return fs.existsSync(`/etc/supervisor/conf.d/${coinRec.code}.conf`)
if (!binaries) throw new Error(`No such coin: ${crypto.code}`) }
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 url = binaries.url
const downloadFile = path.basename(url) const downloadFile = path.basename(url)

View file

@ -25,12 +25,16 @@ const PLUGINS = {
module.exports = {run} module.exports = {run}
function installedFilePath (crypto) { function installedVolumeFilePath (crypto) {
return path.resolve(coinUtils.cryptoDir(crypto), '.installed') return path.resolve(coinUtils.cryptoDir(crypto), '.installed')
} }
function isInstalled (crypto) { function isInstalledVolume (crypto) {
return fs.existsSync(installedFilePath(crypto)) return fs.existsSync(installedVolumeFilePath(crypto))
}
function isInstalledSoftware (crypto) {
return common.isInstalledSoftware(crypto)
} }
function processCryptos (codes) { function processCryptos (codes) {
@ -67,7 +71,7 @@ function setupCrypto (crypto) {
common.es('rm -rf *') common.es('rm -rf *')
common.fetchAndInstall(crypto) common.fetchAndInstall(crypto)
cryptoPlugin.setup(cryptoDir) cryptoPlugin.setup(cryptoDir)
fs.writeFileSync(installedFilePath(crypto), '') fs.writeFileSync(installedVolumeFilePath(crypto), '')
process.chdir(oldDir) process.chdir(oldDir)
} }
@ -79,7 +83,7 @@ function plugin (crypto) {
function run () { function run () {
const choices = _.map(c => { const choices = _.map(c => {
const checked = isInstalled(c) const checked = isInstalledSoftware(c) && isInstalledVolume()
return { return {
name: c.display, name: c.display,
value: c.code, value: c.code,