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()
}
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 = '') {
if (isInstalledSoftware(coinRec)) return
const blockchain = coinRec.code
if (!_.isNil(coinRec.wallet)) {
const supervisorConfigWallet = `[program:${blockchain}-wallet]
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"
`
const supervisorConfigWallet = generateSupervisorConfig(blockchain, walletCmd, true)
writeFile(`/etc/supervisor/conf.d/${coinRec.code}-wallet.conf`, supervisorConfigWallet)
}
const supervisorConfig = `[program:${blockchain}]
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"
`
const supervisorConfig = generateSupervisorConfig(blockchain, cmd)
writeFile(`/etc/supervisor/conf.d/${coinRec.code}.conf`, supervisorConfig)
}
@ -125,7 +120,7 @@ function fetchAndInstall (coinRec) {
const binDir = requiresUpdate ? binaries.defaultDir : binaries.dir
es(`wget -q ${url}`)
coinRec.cryptoCode === 'XMR'
es(`echo ${downloadFile} | awk -F. '{print $NF}'`) === 'bz2'
? es(`tar -xf ${downloadFile}`)
: es(`tar -xzf ${downloadFile}`)

View file

@ -14,16 +14,22 @@ const cryptoRec = utils.getCryptoCurrency('XMR')
const configPath = utils.configPath(cryptoRec, blockchainUtils.blockchainDir())
const walletDir = path.resolve(utils.cryptoDir(cryptoRec, blockchainUtils.blockchainDir()), 'wallets')
const unitScale = cryptoRec.unitScale
const config = jsonRpc.parseConf(configPath)
const rpcConfig = {
username: config['rpc-login'].split(':')[0],
password: config['rpc-login'].split(':')[1],
port: cryptoRec.walletPort || cryptoRec.defaultPort
function rpcConfig () {
try {
const config = jsonRpc.parseConf(configPath)
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) {
return jsonRpc.fetchDigest(rpcConfig, method, params)
return jsonRpc.fetchDigest(rpcConfig(), method, params)
}
function handleError (error) {
@ -55,11 +61,11 @@ function handleError (error) {
}
function openWallet () {
return fetch('open_wallet', { filename: 'Wallet', password: rpcConfig.password })
return fetch('open_wallet', { filename: 'Wallet', password: rpcConfig().password })
}
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(() => fetch('auto_refresh'))
}
@ -173,7 +179,7 @@ function newFunding (account, cryptoCode) {
function cryptoNetwork (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => {
switch(parseInt(rpcConfig.port, 10)) {
switch(parseInt(rpcConfig().port, 10)) {
case 18083:
return 'main'
case 28083: