luci: Restart service on press Save&Apply

This commit is contained in:
remittor
2026-01-26 22:05:22 +03:00
parent c6dfbc5c7e
commit df196ef9a9
4 changed files with 119 additions and 75 deletions

View File

@@ -73,7 +73,7 @@ return view.extend({
}
let svc_boot = status_array[0] ? true : false;
let svc_en = status_array[1]; // stdout: empty or error text
let svc_info = status_array[2]; // stdout: JSON as text
let svc_info = status_array[2]; // dict for services
let proc_list = status_array[3]; // stdout: multiline text
let pkg_dict = status_array[4]; // stdout: installed packages
let stratlist = status_array[5]; // array of strat names
@@ -140,45 +140,21 @@ return view.extend({
let btn = document.getElementById(button);
this.disableButtons(true, btn);
poll.stop();
let errmsg = null;
try {
let exec_cmd = null;
let exec_arg = [ ];
if (action == 'start' || action == 'restart') {
if (tools.checkUnsavedChanges()) {
ui.changes.apply(true);
await new Promise(resolve => setTimeout(resolve, 100));
}
exec_cmd = tools.syncCfgPath;
errmsg = _('Unable to run sync_config.sh script.');
}
if (action == 'reset') {
exec_cmd = tools.defaultCfgPath;
exec_arg = args; // (reset_ipset)(sync) ==> restore all configs + sync config
errmsg = _('Unable to run restore-def-cfg.sh script.');
action = null;
}
if (exec_cmd) {
let res = await fs.exec(exec_cmd, exec_arg);
if (res.code != 0) {
throw Error('res.code = ' + res.code);
}
}
await tools.serviceActionEx(action, args, false);
if (hide_modal) {
ui.hideModal();
}
errmsg = null;
await tools.handleServiceAction(tools.appName, action);
} catch(e) {
let msg = errmsg ? errmsg : _('Unable to run service action') + ' "' + action + '".';
ui.addNotification(null, E('p', msg + ' Error: ' + e.message));
//ui.addNotification(null, E('p', 'Error: ' + e.message));
} finally {
if (!poll.active()) {
poll.start();
}
if (btn && btn_dis) {
setTimeout(() => { btn.disabled = true; }, 0);
}
if (!poll.active()) {
await new Promise(resolve => setTimeout(resolve, 10));
poll.start();
}
}
},
@@ -309,6 +285,8 @@ return view.extend({
}
let cfg = uci.get(tools.appName, 'config');
tools.checkAndRestartSvc(status_array[2]); // svc_info
let pkgdict = status_array[4];
if (pkgdict == null) {
ui.addNotification(null, E('p', _('Unable to enumerate installed packages') + ': render()'));