fix(portal): Improve service scanning reliability
- Use pgrep without -f flag (OpenWrt compatibility) - Use printf instead of echo for reliable output - Add explicit /bin/sh path - Add error logging for debugging Fixes 0/0 services display on dashboard. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c33a9650e7
commit
369ef86487
@ -84,27 +84,32 @@ return view.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
scanInitServices: function() {
|
scanInitServices: function() {
|
||||||
// Scan /etc/init.d for service status
|
// Scan /etc/init.d for service status using a temp file approach
|
||||||
return fs.exec('sh', ['-c',
|
// which is more reliable with LuCI's fs.exec
|
||||||
|
var script =
|
||||||
'for s in /etc/init.d/*; do ' +
|
'for s in /etc/init.d/*; do ' +
|
||||||
'[ -x "$s" ] || continue; ' +
|
'[ -x "$s" ] || continue; ' +
|
||||||
'n=$(basename "$s"); ' +
|
'n=$(basename "$s"); ' +
|
||||||
'r="stopped"; ' +
|
'r=stopped; ' +
|
||||||
'pgrep -f "$n" >/dev/null 2>&1 && r="running"; ' +
|
'pgrep "$n" >/dev/null 2>&1 && r=running; ' +
|
||||||
'echo "$n:$r"; ' +
|
'printf "%s:%s\\n" "$n" "$r"; ' +
|
||||||
'done'
|
'done';
|
||||||
]).then(function(res) {
|
|
||||||
|
return fs.exec('/bin/sh', ['-c', script]).then(function(res) {
|
||||||
var services = {};
|
var services = {};
|
||||||
if (res && res.stdout) {
|
if (res && res.stdout) {
|
||||||
res.stdout.trim().split('\n').forEach(function(line) {
|
res.stdout.trim().split('\n').forEach(function(line) {
|
||||||
var parts = line.split(':');
|
var parts = line.split(':');
|
||||||
if (parts.length === 2) {
|
if (parts.length === 2 && parts[0] && parts[1]) {
|
||||||
services[parts[0]] = parts[1];
|
services[parts[0]] = parts[1];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return services;
|
return services;
|
||||||
}).catch(function() { return {}; });
|
}).catch(function(err) {
|
||||||
|
console.error('scanInitServices failed:', err);
|
||||||
|
return {};
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(data) {
|
render: function(data) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user