refactor: supervisor config pull up method

fix: small fixes
This commit is contained in:
Sérgio Salgado 2021-07-19 15:53:48 +01:00
parent c0808e9bd7
commit 048971fdb3
2 changed files with 29 additions and 28 deletions

View file

@ -76,33 +76,28 @@ function es (cmd) {
return res.toString() return res.toString()
} }
function generateSupervisorConfig (cryptoCode, command, isWallet = false) {
return `[program:${cryptoCode}${isWallet ? `-wallet` : ``}]
command=nice ${command}
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/${cryptoCode}${isWallet ? `-wallet` : ``}.err.log
stdout_logfile=/var/log/supervisor/${cryptoCode}${isWallet ? `-wallet` : ``}.out.log
environment=HOME="/root"
`
}
function writeSupervisorConfig (coinRec, cmd, walletCmd = '') { function writeSupervisorConfig (coinRec, cmd, walletCmd = '') {
if (isInstalledSoftware(coinRec)) return if (isInstalledSoftware(coinRec)) return
const blockchain = coinRec.code const blockchain = coinRec.code
if (!_.isNil(coinRec.wallet)) { if (!_.isNil(coinRec.wallet)) {
const supervisorConfigWallet = `[program:${blockchain}-wallet] const supervisorConfigWallet = generateSupervisorConfig(blockchain, walletCmd, true)
command=nice ${walletCmd}
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/${blockchain}-wallet.err.log
stdout_logfile=/var/log/supervisor/${blockchain}-wallet.out.log
environment=HOME="/root"
`
writeFile(`/etc/supervisor/conf.d/${coinRec.code}-wallet.conf`, supervisorConfigWallet) writeFile(`/etc/supervisor/conf.d/${coinRec.code}-wallet.conf`, supervisorConfigWallet)
} }
const supervisorConfig = `[program:${blockchain}] const supervisorConfig = generateSupervisorConfig(blockchain, cmd)
command=nice ${cmd}
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/${blockchain}.err.log
stdout_logfile=/var/log/supervisor/${blockchain}.out.log
environment=HOME="/root"
`
writeFile(`/etc/supervisor/conf.d/${coinRec.code}.conf`, supervisorConfig) writeFile(`/etc/supervisor/conf.d/${coinRec.code}.conf`, supervisorConfig)
} }
@ -125,7 +120,7 @@ function fetchAndInstall (coinRec) {
const binDir = requiresUpdate ? binaries.defaultDir : binaries.dir const binDir = requiresUpdate ? binaries.defaultDir : binaries.dir
es(`wget -q ${url}`) es(`wget -q ${url}`)
coinRec.cryptoCode === 'XMR' es(`echo ${downloadFile} | awk -F. '{print $NF}'`) === 'bz2'
? es(`tar -xf ${downloadFile}`) ? es(`tar -xf ${downloadFile}`)
: es(`tar -xzf ${downloadFile}`) : es(`tar -xzf ${downloadFile}`)

View file

@ -14,16 +14,22 @@ const cryptoRec = utils.getCryptoCurrency('XMR')
const configPath = utils.configPath(cryptoRec, blockchainUtils.blockchainDir()) const configPath = utils.configPath(cryptoRec, blockchainUtils.blockchainDir())
const walletDir = path.resolve(utils.cryptoDir(cryptoRec, blockchainUtils.blockchainDir()), 'wallets') const walletDir = path.resolve(utils.cryptoDir(cryptoRec, blockchainUtils.blockchainDir()), 'wallets')
const unitScale = cryptoRec.unitScale const unitScale = cryptoRec.unitScale
const config = jsonRpc.parseConf(configPath)
const rpcConfig = { function rpcConfig () {
username: config['rpc-login'].split(':')[0], try {
password: config['rpc-login'].split(':')[1], const config = jsonRpc.parseConf(configPath)
port: cryptoRec.walletPort || cryptoRec.defaultPort return {
username: config['rpc-login'].split(':')[0],
password: config['rpc-login'].split(':')[1],
port: cryptoRec.walletPort || cryptoRec.defaultPort
}
} catch (err) {
throw new Error('wallet is currently not installed')
}
} }
function fetch (method, params) { function fetch (method, params) {
return jsonRpc.fetchDigest(rpcConfig, method, params) return jsonRpc.fetchDigest(rpcConfig(), method, params)
} }
function handleError (error) { function handleError (error) {
@ -55,11 +61,11 @@ function handleError (error) {
} }
function openWallet () { function openWallet () {
return fetch('open_wallet', { filename: 'Wallet', password: rpcConfig.password }) return fetch('open_wallet', { filename: 'Wallet', password: rpcConfig().password })
} }
function createWallet () { function createWallet () {
return fetch('create_wallet', { filename: 'Wallet', password: rpcConfig.password, language: 'English' }) return fetch('create_wallet', { filename: 'Wallet', password: rpcConfig().password, language: 'English' })
.then(() => new Promise(() => setTimeout(() => openWallet(), 3000))) .then(() => new Promise(() => setTimeout(() => openWallet(), 3000)))
.then(() => fetch('auto_refresh')) .then(() => fetch('auto_refresh'))
} }
@ -173,7 +179,7 @@ function newFunding (account, cryptoCode) {
function cryptoNetwork (account, cryptoCode) { function cryptoNetwork (account, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => { .then(() => {
switch(parseInt(rpcConfig.port, 10)) { switch(parseInt(rpcConfig().port, 10)) {
case 18083: case 18083:
return 'main' return 'main'
case 28083: case 28083: