Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions app/server/config/integration/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,37 @@ export default class ProcIntegration extends Integration<T> {

log.debug('config', 'Found Headscale processes: %o', pids);
if (pids.length > 1) {
log.error(
log.warn(
'config',
'Found %d Headscale processes: %s',
pids.length,
pids.join(', '),
);
return false;
}

log.debug('config', 'Checking if any of them have Parent PID = 1, assuming thats the correct PID');
const ppidRegex = /(?:PPid:\s)(\d+)(?:\n?)/;
for (const pid of pids) {
const pidStatusPath = join('/proc', pid.toString(), 'status');
try {
log.debug('config', 'Reading %s', pidStatusPath);
const pidData = await readFile(pidStatusPath, 'utf8');
const ppidResult = pidData.match(ppidRegex);

if (ppidResult !== null) {
const potentialPPid = Number.parseInt(ppidResult[1], 10);
if (potentialPPid === 1) {
this.pid = pid;
log.info('config', 'Found potential Headscale process with PID: %d based on Parent PID = 1', this.pid);
return true;
}
}
} catch (error) {
log.error('config', 'Failed to read %s: %s', pidStatusPath, error);
}
}

return false;
}

if (pids.length === 0) {
log.error('config', 'Could not find Headscale process');
Expand Down