domotz-remote-pawn
Version:
Domotz Agent
61 lines (58 loc) • 2.65 kB
JavaScript
/** This file is part of Domotz Agent.
* Copyright (C) 2025 Domotz Ltd
*
* Domotz Agent is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Domotz Agent is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>.
*
* Created by Andrea Azzara <a.azzara@domotz.com> on 23/01/2025.
*/
module.exports.command = function (message, resourceLocator) {
var platform = resourceLocator.utils.platform;
var myConsole = resourceLocator.log.decorateLogs();
var childProcess = require('child_process');
return {
describe: function () {
return 'System Restart';
},
execute: function (callback) {
if (platform.isUbuntuCorePrivate()) {
var rebootDelay = (message && message.payload && message.payload.reboot_delay) || 2000;
myConsole.info('Performing system reboot');
setTimeout(function () {
childProcess.exec(
'dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.Reboot boolean:true',
function (error, stdout, stderr) {
if (error) {
myConsole.error('Error executing reboot command: ' + error);
callback({
error: error.toString(),
});
} else {
myConsole.info('Reboot command executed successfully');
callback({
error: null,
});
}
}
);
}, rebootDelay);
} else {
var systemRebootIsDisabledForThisPlatform = 'System reboot is disabled for this platform';
myConsole.info(systemRebootIsDisabledForThisPlatform);
callback({
error: systemRebootIsDisabledForThisPlatform,
});
}
},
};
};