Skip to content

Commit

Permalink
Merge pull request #1181 from siiky/fix/lam-1123/primordials
Browse files Browse the repository at this point in the history
LAM-1123 fix: Sencha upgrade
  • Loading branch information
RafaelTaranto authored Sep 13, 2024
2 parents 07b3462 + b86f128 commit e37b100
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 32 deletions.
58 changes: 27 additions & 31 deletions deploy/codebase/lamassu-machine-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand Down Expand Up @@ -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`),
Expand Down
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 e37b100

Please sign in to comment.