Skip to content

Commit

Permalink
feat: gunzip Node.js executable
Browse files Browse the repository at this point in the history
  • Loading branch information
siiky committed Sep 12, 2024
1 parent cd476fd commit c7e5a9f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion deploy/node-update/nodejs-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const unlink = path => new Promise((resolve, reject) =>
fs.unlink(path, err => err ? reject(err) : resolve())
)

const fileExists = path => new Promise(resolve => fs.access(path, err => resolve(!!err)))

const execFile = (cmd, args) => new Promise((resolve, reject) =>
child_process.execFile(cmd, args, null, err => err ? reject(err) : resolve())
)
Expand All @@ -44,9 +46,10 @@ const mv = args => execFile('mv', args)
const rm = args => execFile('rm', args)
const sed = args => execFile('sed', args)
const supervisorctl = args => execFile('supervisorctl', args)
const tar = args => execFile('tar', args)


const PACKAGE = path.resolve(__dirname) // TODO: confirm this
const PACKAGE = path.resolve(__dirname)
const OPT = '/opt/'
const BACKUP = path.join(OPT, 'backup/')

Expand All @@ -56,6 +59,7 @@ const LAMASSU_MACHINE_BACKUP = path.join(BACKUP, 'lamassu-machine/')
const NODE = '/usr/bin/node'
const NODE_BACKUP = path.join(BACKUP, 'node')
const NEW_NODE = path.join(PACKAGE, 'node')
const NEW_NODE_TGZ = path.join(PACKAGE, 'node.tgz')

const SUPERVISOR_CONF = '/etc/supervisor/conf.d/'
const WATCHDOG_CONF = path.join(SUPERVISOR_CONF, 'lamassu-watchdog.conf')
Expand Down Expand Up @@ -142,6 +146,20 @@ const installOldServices = () => {
]))
}

const gunzip_new_node = () => {
console.log("Checking if the new Node.js executable already exists")
return fileExists(NEW_NODE)
.then(exists => {
if (exists) {
console.log("Node.js executable exists -- skipping gunzip")
return Promise.resolve()
} else {
console.log("Gunzipping Node.js executable")
return tar(['xf', NEW_NODE_TGZ, '-C', PACKAGE])
}
})
}

// Install new node
const upgradeNode = () => {
console.log("Upgrading Node.js executable")
Expand All @@ -154,6 +172,7 @@ const upgradeNode = () => {
const upgrade = () => {
console.log("Starting Node.js upgrade process")
return ensure_x64
.then(gunzip_new_node)
.then(respawn_if_needed)
.then(stopSupervisorServices)
.then(backupMachine)
Expand Down Expand Up @@ -197,6 +216,7 @@ const removeBackup = () => {
const downgrade = () => {
console.log("Starting Node.js downgrade process")
return ensure_x64
.then(gunzip_new_node)
.then(respawn_if_needed)
.then(stopSupervisorServices)
.then(downgradeMachine)
Expand Down

0 comments on commit c7e5a9f

Please sign in to comment.