diff --git a/deploy/codebase/lamassu-machine-manager.js b/deploy/codebase/lamassu-machine-manager.js index 830b2735a..421e48832 100644 --- a/deploy/codebase/lamassu-machine-manager.js +++ b/deploy/codebase/lamassu-machine-manager.js @@ -39,7 +39,8 @@ function updateUdev (cb) { if (hardwareCode !== 'aaeon') return cb() return async.series([ async.apply(command, `cp ${udevPath}/* /etc/udev/rules.d/`), - async.apply(command, 'udevadm control --reload-rules && udevadm trigger'), + async.apply(command, 'udevadm control --reload-rules'), + async.apply(command, 'udevadm trigger'), ], (err) => { if (err) throw err; cb() @@ -50,35 +51,30 @@ function updateSupervisor (cb) { console.log("Updating Supervisor services") if (hardwareCode === 'aaeon') return cb() - const getOSUser = () => - fs.promises.readFile('/etc/os-release', { encoding: 'utf8' }) - .then( - text => text - .split('\n') - .includes('IMAGE_ID=lamassu-machine-xubuntu') ? - 'lamassu' : - 'ubilinux', - _err => 'ubilinux', - ) - - (machineWithMultipleCodes.includes(hardwareCode) ? getOSUser() : Promise.resolve('lamassu')) - .then(osuser => { - cp.exec('systemctl enable supervisor', {timeout: TIMEOUT}, function(err) { - if (err) { - console.log('failure activating systemctl') - } - - async.series([ - async.apply(command, `cp ${supervisorPath}/* /etc/supervisor/conf.d/`), - async.apply(command, `sed -i 's|^user=.*\$|user=${osuser}|;' /etc/supervisor/conf.d/lamassu-browser.conf || true`), - async.apply(command, 'supervisorctl update'), - async.apply(command, 'supervisorctl restart all'), - ], (err) => { - if (err) throw err; - cb() - }) - }) - }) + const isLMX = () => + fs.readFileSync('/etc/os-release', { encoding: 'utf8' }) + .split('\n') + .includes('IMAGE_ID=lamassu-machine-xubuntu') + + const getOSUser = () => { + try { + return (!machineWithMultipleCodes.includes(hardwareCode) || isLMX()) ? 'lamassu' : 'ubilinux' + } catch (err) { + return 'ubilinux' + } + } + + const osuser = getOSUser() + + async.series([ + async.apply(command, `cp ${supervisorPath}/* /etc/supervisor/conf.d/`), + async.apply(command, `sed -i 's|^user=.*\$|user=${osuser}|;' /etc/supervisor/conf.d/lamassu-browser.conf || true`), + async.apply(command, 'supervisorctl update'), + async.apply(command, 'supervisorctl restart all'), + ], err => { + if (err) throw err; + cb() + }) } function updateAcpChromium (cb) { @@ -152,7 +148,7 @@ const upgrade = () => { const commands = [ async.apply(command, `tar zxf ${basePath}/package/subpackage.tgz -C ${basePath}/package/`), - async.apply(command, `rm -rf ${applicationParentFolder}/lamassu-machine/node_modules/genmega`), + async.apply(command, `rm -rf ${applicationParentFolder}/lamassu-machine/node_modules/`), async.apply(command, `cp -PR ${basePath}/package/subpackage/lamassu-machine ${applicationParentFolder}`), async.apply(command, `cp -PR ${basePath}/package/subpackage/hardware/${hardwareCode}/node_modules ${applicationParentFolder}/lamassu-machine/`), async.apply(command, `mv ${applicationParentFolder}/lamassu-machine/verify/verify.${arch} ${applicationParentFolder}/lamassu-machine/verify/verify`), diff --git a/deploy/node-update/nodejs-manager.js b/deploy/node-update/nodejs-manager.js index ad8b3080f..b00d1099b 100644 --- a/deploy/node-update/nodejs-manager.js +++ b/deploy/node-update/nodejs-manager.js @@ -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()) ) @@ -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/') @@ -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') @@ -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") @@ -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) @@ -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)