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}]
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

View file

@ -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)

View file

@ -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,