system: return uptime and reboot required

This commit is contained in:
Girish Ramakrishnan
2023-12-04 00:46:12 +01:00
parent 72083f59cd
commit eb64bd296a
4 changed files with 16 additions and 10 deletions

View File

@@ -2,7 +2,7 @@
exports = module.exports = {
reboot,
isRebootRequired,
getInfo,
getUbuntuVersion,
getDisks,
getSwaps,
@@ -279,9 +279,15 @@ async function reboot() {
if (error) debug('reboot: could not reboot. %o', error);
}
async function isRebootRequired() {
async function getInfo() {
// https://serverfault.com/questions/92932/how-does-ubuntu-keep-track-of-the-system-restart-required-flag-in-motd
return fs.existsSync('/var/run/reboot-required');
const rebootRequired = fs.existsSync('/var/run/reboot-required');
const uptime = safe.child_process.execSync('uptime -s', { encoding: 'utf8' });
return {
uptime,
rebootRequired
};
}
async function startUpdateDiskUsage() {
@@ -330,7 +336,7 @@ async function getBlockDevices() {
}
async function checkRebootRequired() {
const rebootRequired = await isRebootRequired();
const { rebootRequired } = await getInfo();
if (rebootRequired) {
await notifications.alert(notifications.ALERT_REBOOT, 'Reboot Required', 'To finish ubuntu security updates, a reboot is necessary.', { persist: true });
} else {