Skip to content

Commit

Permalink
Merge pull request #1213 from siiky/fix/lam-1205/supervisor-after-dm
Browse files Browse the repository at this point in the history
LAM-1205 Black screens when booting but OS and l-m are still up
  • Loading branch information
RafaelTaranto authored Nov 6, 2024
2 parents ec8b971 + e9ce8d0 commit 7b35435
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 21 deletions.
60 changes: 42 additions & 18 deletions deploy/codebase/lamassu-machine-manager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';

const cp = require('child_process');
const fs = require('fs');
const { mkdir, writeFile } = require('fs/promises');
const path = require('path');
const async = require('./async');
const cp = require('child_process');
const report = require('./report').report;

const hardwareCode = process.argv[2];
Expand All @@ -14,7 +16,7 @@ const packagePath = `${basePath}/package/subpackage`

const machineWithMultipleCodes = ['upboard', 'up4000', 'coincloud', 'generalbytes', 'genmega']

const path = machineWithMultipleCodes.includes(hardwareCode) ?
const hardwarePath = machineWithMultipleCodes.includes(hardwareCode) ?
`${packagePath}/hardware/${hardwareCode}/${machineCode}` :
`${packagePath}/hardware/${hardwareCode}`

Expand All @@ -37,6 +39,24 @@ function command(cmd, cb) {
});
}

const isLMX = () => {
try {
return fs.readFileSync('/etc/os-release', { encoding: 'utf8' })
.split('\n')
.includes('IMAGE_ID=lamassu-machine-xubuntu')
} catch (err) {
return false
}
}

const getOSUser = () => {
try {
return (!machineWithMultipleCodes.includes(hardwareCode) || isLMX()) ? 'lamassu' : 'ubilinux'
} catch (err) {
return 'ubilinux'
}
}

function updateUdev (cb) {
LOG("Updating udev rules")
if (hardwareCode !== 'aaeon') return cb()
Expand All @@ -54,19 +74,6 @@ function updateSupervisor (cb) {
LOG("Updating Supervisor services")
if (hardwareCode === 'aaeon') return 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 getServices = () => {
const extractServices = stdout => {
const services = stdout
Expand Down Expand Up @@ -107,6 +114,22 @@ function updateSupervisor (cb) {
})
}

const updateSystemd = cb => {
LOG("Make Supervisor start after X")
const override = dm => `[Unit]\nAfter=${dm}.service\nWants=${dm}.service\n`
const SUPERVISOR_OVERRIDE = "/etc/systemd/system/supervisor.service.d/override.conf"
return mkdir(path.dirname(SUPERVISOR_OVERRIDE), { recursive: true })
.then(() => isLMX() ? 'lightdm' : 'sddm') // Assume Ubilinux if not l-m-x
.then(dm => writeFile(SUPERVISOR_OVERRIDE, override(dm), { mode: 0o600, flush: true }))
.then(() => new Promise((resolve, reject) =>
cp.execFile('systemctl', ['daemon-reload'], { timeout: 10000 },
(error, _stdout, _stderr) => error ? reject(error) : resolve()
)
))
.then(() => cb())
.catch(err => cb(err))
}

function restartWatchdogService (cb) {
async.series([
async.apply(command, 'supervisorctl update lamassu-watchdog'),
Expand All @@ -121,8 +144,8 @@ function updateAcpChromium (cb) {
LOG("Updating ACP Chromium")
if (hardwareCode !== 'aaeon') return cb()
return async.series([
async.apply(command, `cp ${path}/sencha-chrome.conf /home/iva/.config/upstart/`),
async.apply(command, `cp ${path}/start-chrome /home/iva/`),
async.apply(command, `cp ${hardwarePath}/sencha-chrome.conf /home/iva/.config/upstart/`),
async.apply(command, `cp ${hardwarePath}/start-chrome /home/iva/`),
], function(err) {
if (err) throw err;
cb()
Expand All @@ -133,7 +156,7 @@ function installDeviceConfig (cb) {
LOG("Installing `device_config.json`")
try {
const currentDeviceConfigPath = `${applicationParentFolder}/lamassu-machine/device_config.json`
const newDeviceConfigPath = `${path}/device_config.json`
const newDeviceConfigPath = `${hardwarePath}/device_config.json`

// Updates don't necessarily need to carry a device_config.json file
if (!fs.existsSync(newDeviceConfigPath)) return cb()
Expand Down Expand Up @@ -204,6 +227,7 @@ const upgrade = () => {
async.apply(command, `mv ${applicationParentFolder}/lamassu-machine/camera-streamer/camera-streamer.${arch} ${applicationParentFolder}/lamassu-machine/camera-streamer/camera-streamer`),
async.apply(installDeviceConfig),
async.apply(updateSupervisor),
async.apply(updateSystemd),
async.apply(updateUdev),
async.apply(updateAcpChromium),
async.apply(report, null, 'finished.'),
Expand Down
13 changes: 10 additions & 3 deletions lib/update/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,21 @@ Updater.prototype._update = function _update () {

function noop () {}

const readConnectionInfo = dataPath => {
try {
const connectionInfoPath = path.resolve(dataPath, 'connection_info.json')
return JSON.parse(fs.readFileSync(connectionInfoPath))
} catch (err) {
return {}
}
}

Updater.prototype.updateHeaders = function updateHeaders (options) {
var dataPath = path.resolve(__dirname, '..', '..', this.config.dataPath)
var machineInfo = machineInfoLoader.load(dataPath)
var watchdogInfo = watchdogInfoLoader.load(dataPath)

var connectionInfoPath = path.resolve(dataPath, 'connection_info.json')
const connectionInfo = JSON.parse(fs.readFileSync(connectionInfoPath))

const connectionInfo = readConnectionInfo(dataPath)
if (connectionInfo.host) {
options = _.assign(options, {
'device-host': crypto.createHash('sha256').update(connectionInfo.host).digest('hex')
Expand Down

0 comments on commit 7b35435

Please sign in to comment.