luci-mod-system: use ubus method for reboot

It's more generic & convenient than hardcoding /sbin/reboot executable
path. procd provides "reboot" method since 2016.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
This commit is contained in:
Rafał Miłecki 2020-06-18 15:25:18 +02:00
parent 77af092511
commit 96bb528ccc
2 changed files with 12 additions and 5 deletions

View file

@ -1,9 +1,15 @@
'use strict'; 'use strict';
'require view'; 'require view';
'require fs'; 'require rpc';
'require ui'; 'require ui';
'require uci'; 'require uci';
var callReboot = rpc.declare({
object: 'system',
method: 'reboot',
expect: { result: 0 }
});
return view.extend({ return view.extend({
load: function() { load: function() {
return uci.changes(); return uci.changes();
@ -31,9 +37,9 @@ return view.extend({
}, },
handleReboot: function(ev) { handleReboot: function(ev) {
return fs.exec('/sbin/reboot').then(function(res) { return callReboot().then(function(res) {
if (res.code != 0) { if (res != 0) {
L.ui.addNotification(null, E('p', _('The reboot command failed with code %d').format(res.code))); L.ui.addNotification(null, E('p', _('The reboot command failed with code %d').format(res)));
L.raise('Error', 'Reboot failed'); L.raise('Error', 'Reboot failed');
} }

View file

@ -160,7 +160,8 @@
"/sbin/reboot": [ "exec" ] "/sbin/reboot": [ "exec" ]
}, },
"ubus": { "ubus": {
"file": [ "exec" ] "file": [ "exec" ],
"system": [ "reboot" ]
} }
} }
} }