fix(portal): Add helper script for reliable service enumeration
- Create /usr/bin/secubox-services-status helper script - Update portal scanInitServices to use helper script - Fallback to inline script if helper not available - Fixes 0/0 services display caused by fs.exec output buffering Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
369ef86487
commit
20cbf0adf3
@ -84,18 +84,9 @@ return view.extend({
|
||||
},
|
||||
|
||||
scanInitServices: function() {
|
||||
// Scan /etc/init.d for service status using a temp file approach
|
||||
// which is more reliable with LuCI's fs.exec
|
||||
var script =
|
||||
'for s in /etc/init.d/*; do ' +
|
||||
'[ -x "$s" ] || continue; ' +
|
||||
'n=$(basename "$s"); ' +
|
||||
'r=stopped; ' +
|
||||
'pgrep "$n" >/dev/null 2>&1 && r=running; ' +
|
||||
'printf "%s:%s\\n" "$n" "$r"; ' +
|
||||
'done';
|
||||
|
||||
return fs.exec('/bin/sh', ['-c', script]).then(function(res) {
|
||||
// Use helper script for reliable output capture
|
||||
// Falls back to inline script if helper not available
|
||||
return fs.exec('/usr/bin/secubox-services-status', []).then(function(res) {
|
||||
var services = {};
|
||||
if (res && res.stdout) {
|
||||
res.stdout.trim().split('\n').forEach(function(line) {
|
||||
@ -106,9 +97,25 @@ return view.extend({
|
||||
});
|
||||
}
|
||||
return services;
|
||||
}).catch(function(err) {
|
||||
console.error('scanInitServices failed:', err);
|
||||
return {};
|
||||
}).catch(function() {
|
||||
// Fallback: use inline script
|
||||
return fs.exec('/bin/sh', ['-c',
|
||||
'for s in /etc/init.d/*; do [ -x "$s" ] || continue; ' +
|
||||
'n=$(basename "$s"); r=stopped; ' +
|
||||
'pgrep -f "$n" >/dev/null 2>&1 && r=running; ' +
|
||||
'printf "%s:%s\\n" "$n" "$r"; done'
|
||||
]).then(function(res) {
|
||||
var services = {};
|
||||
if (res && res.stdout) {
|
||||
res.stdout.trim().split('\n').forEach(function(line) {
|
||||
var parts = line.split(':');
|
||||
if (parts.length === 2 && parts[0] && parts[1]) {
|
||||
services[parts[0]] = parts[1];
|
||||
}
|
||||
});
|
||||
}
|
||||
return services;
|
||||
}).catch(function() { return {}; });
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@ -87,6 +87,9 @@ define Package/secubox-core/install
|
||||
$(INSTALL_BIN) ./root/usr/sbin/secubox-feedback $(1)/usr/sbin/
|
||||
$(INSTALL_BIN) ./root/usr/sbin/secubox-tftp-recovery $(1)/usr/sbin/
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) ./root/usr/bin/secubox-services-status $(1)/usr/bin/
|
||||
|
||||
# TFTP Recovery init script
|
||||
$(INSTALL_BIN) ./root/etc/init.d/secubox-tftp-recovery $(1)/etc/init.d/
|
||||
|
||||
|
||||
11
package/secubox/secubox-core/root/usr/bin/secubox-services-status
Executable file
11
package/secubox/secubox-core/root/usr/bin/secubox-services-status
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
# SecuBox Services Status - List init.d services with running status
|
||||
# Used by LuCI portal for reliable service enumeration
|
||||
|
||||
for s in /etc/init.d/*; do
|
||||
[ -x "$s" ] || continue
|
||||
n=$(basename "$s")
|
||||
r=stopped
|
||||
pgrep -f "$n" >/dev/null 2>&1 && r=running
|
||||
printf "%s:%s\n" "$n" "$r"
|
||||
done
|
||||
Loading…
Reference in New Issue
Block a user