Skip to content

Commit 3e382fa

Browse files
Fix/system ports regression (#77)
* fix: restore system port detection when running containerized * docs: update changelog for system port detection fix
1 parent af3ccd7 commit 3e382fa

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ All notable changes to portracker will be documented in this file.
88

99
- **Reverse Proxy Support**: New `HOST_OVERRIDE` environment variable allows specifying the hostname used in port links when running behind a reverse proxy (fixes #51)
1010

11+
### Fixed
12+
13+
- **System Port Detection**: Restored system port detection (SSH, SMB, etc.) when running in containerized environments.
14+
1115
### UI
1216

1317
- **Favicon**: Dark mode support - favicon now adapts to system theme (black on light, white on dark)

backend/collectors/truenas_collector.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,10 @@ class TrueNASCollector extends BaseCollector {
641641
const isContainerized = this._detectContainerizedEnvironment();
642642
this.logInfo(`Container environment detected: ${isContainerized}`);
643643

644-
if (this.procParser && !isContainerized) {
644+
if (this.procParser) {
645645
try {
646646
this.logInfo('Attempting primary method: Enhanced /proc filesystem parsing');
647+
this.logInfo('Note: With pid:host, proc-parser uses /proc/1/net/tcp to access host network namespace');
647648
const procWorks = await this.procParser.testProcAccess();
648649

649650
if (procWorks) {
@@ -673,32 +674,35 @@ class TrueNASCollector extends BaseCollector {
673674
} catch (procErr) {
674675
this.logWarn('Failed to get ports via enhanced /proc parsing:', procErr.message);
675676
}
676-
} else if (isContainerized) {
677-
this.logInfo('Containerized environment detected, skipping /proc method and using network commands');
678677
}
679678

680679
try {
681680
this.logInfo('Attempting enhanced ss command with host namespace access');
682681
let ssOutput = '';
683682
let ssMethod = 'container';
684683

685-
if (!isContainerized) {
684+
if (isContainerized) {
686685
try {
686+
this.logInfo('Containerized: trying nsenter to access host network namespace');
687687
const { stdout: nsenterOutput } = await execAsync('nsenter -t 1 -n ss -tulpn 2>/dev/null');
688688
if (nsenterOutput && nsenterOutput.trim().length > 100) {
689689
ssOutput = nsenterOutput;
690690
ssMethod = 'nsenter-host';
691691
this.logInfo('Successfully accessed host network namespace via nsenter');
692692
}
693693
} catch (nsenterErr) {
694-
this.logInfo(`nsenter method failed: ${nsenterErr.message}, falling back to container ss`);
694+
this.logWarn(`nsenter method failed: ${nsenterErr.message}, falling back to container ss`);
695+
const msg = String(nsenterErr?.message || '').toLowerCase();
696+
if (msg.includes('permission denied') || msg.includes('operation not permitted')) {
697+
this.logWarn('Hint: nsenter requires pid: "host" and cap_add: [SYS_ADMIN] in docker-compose.yml');
698+
}
695699
}
696700
}
697701

698702
if (!ssOutput) {
699703
const { stdout } = await execAsync('ss -tulpn 2>/dev/null');
700704
ssOutput = stdout;
701-
ssMethod = 'container';
705+
ssMethod = isContainerized ? 'container-fallback' : 'local';
702706
}
703707

704708
const ports = this._parseSSOutput(ssOutput, ssMethod);

0 commit comments

Comments
 (0)