feat: backport remote BTC node support
This commit is contained in:
parent
24473de6d5
commit
1b6ba5e6dc
15 changed files with 272 additions and 55 deletions
32
tools/migrate-env.js
Normal file
32
tools/migrate-env.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const _ = require('lodash/fp')
|
||||
const setEnvVariable = require('./set-env-var')
|
||||
|
||||
const ENV_PATH = process.env.NODE_ENV === 'production' ? path.resolve('/etc', 'lamassu', '.env') : path.resolve(__dirname, '../.env')
|
||||
const BACKUP_TIMESTAMP = Date.now()
|
||||
const BACKUP_PATH = `${ENV_PATH}-${BACKUP_TIMESTAMP}`
|
||||
|
||||
const migrateEnv = newVars => {
|
||||
try {
|
||||
fs.copyFileSync(ENV_PATH, BACKUP_PATH)
|
||||
_.forEach(it => {
|
||||
setEnvVariable(it[0], it[1], { ENV_PATH })
|
||||
}, newVars)
|
||||
fs.unlinkSync(BACKUP_PATH)
|
||||
console.log('Environment migration successful')
|
||||
} catch (e) {
|
||||
// Rollback the migration and restore the backup file
|
||||
if (fs.existsSync(BACKUP_PATH)) {
|
||||
console.log('Rolling back the environment migration...')
|
||||
fs.copyFileSync(BACKUP_PATH, ENV_PATH)
|
||||
fs.unlinkSync(BACKUP_PATH)
|
||||
console.log('Rollback finished')
|
||||
}
|
||||
console.log('Environment migration failed')
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = migrateEnv
|
||||
Loading…
Add table
Add a link
Reference in a new issue