fix: improve headscale proc detection

Check if command line also includes 'serve'.
Move command line processing logic into a helper function.
This commit is contained in:
Giorgi Lekveishvili 2025-04-27 08:20:41 +04:00 committed by Aarnav Tale
parent 59874ca749
commit a993908ebc
No known key found for this signature in database
3 changed files with 7 additions and 2 deletions

View File

@ -0,0 +1,3 @@
export function isHeadscaleServeCmd(cmdline: string): boolean {
return cmdline.includes('headscale') && cmdline.includes("serve");
}

View File

@ -8,6 +8,7 @@ import { ApiClient } from '~/server/headscale/api-client';
import log from '~/utils/log';
import { HeadplaneConfig } from '../schema';
import { Integration } from './abstract';
import { isHeadscaleServeCmd } from './cmdline.ts';
// TODO: Upgrade to the new CoreV1Api from @kubernetes/client-node
type T = NonNullable<HeadplaneConfig['integration']>['kubernetes'];
@ -162,7 +163,7 @@ export default class KubernetesIntegration extends Integration<T> {
try {
log.debug('config', 'Reading %s', path);
const data = await readFile(path, 'utf8');
if (data.includes('headscale')) {
if (isHeadscaleServeCmd(data)) {
return pid;
}
} catch (error) {

View File

@ -7,6 +7,7 @@ import { ApiClient } from '~/server/headscale/api-client';
import log from '~/utils/log';
import { HeadplaneConfig } from '../schema';
import { Integration } from './abstract';
import { isHeadscaleServeCmd } from './cmdline.ts';
type T = NonNullable<HeadplaneConfig['integration']>['proc'];
export default class ProcIntegration extends Integration<T> {
@ -38,7 +39,7 @@ export default class ProcIntegration extends Integration<T> {
try {
log.debug('config', 'Reading %s', path);
const data = await readFile(path, 'utf8');
if (data.includes('headscale')) {
if (isHeadscaleServeCmd(data)) {
return pid;
}
} catch (error) {