mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
feat: Add in more options in the adding of a daemon
This commit is contained in:
@@ -19,19 +19,36 @@ export function containsAddress(x: string, port: number) {
|
||||
export async function checkPortListening(
|
||||
effects: Effects,
|
||||
port: number,
|
||||
{
|
||||
error = `Port ${port} is not listening`,
|
||||
message = `Port ${port} is available`,
|
||||
} = {},
|
||||
options: {
|
||||
errorMessage: string
|
||||
successMessage: string
|
||||
timeoutMessage?: string
|
||||
timeout?: number
|
||||
},
|
||||
): Promise<CheckResult> {
|
||||
const hasAddress =
|
||||
containsAddress(await effects.runCommand(`cat /proc/net/tcp`), port) ||
|
||||
containsAddress(await effects.runCommand("cat /proc/net/udp"), port)
|
||||
if (hasAddress) {
|
||||
return { status: "passing", message }
|
||||
}
|
||||
return {
|
||||
status: "failing",
|
||||
message: error,
|
||||
}
|
||||
return Promise.race<CheckResult>([
|
||||
Promise.resolve().then(async () => {
|
||||
const hasAddress =
|
||||
containsAddress(await effects.runCommand(`cat /proc/net/tcp`), port) ||
|
||||
containsAddress(await effects.runCommand("cat /proc/net/udp"), port)
|
||||
if (hasAddress) {
|
||||
return { status: "passing", message: options.successMessage }
|
||||
}
|
||||
return {
|
||||
status: "failing",
|
||||
message: options.errorMessage,
|
||||
}
|
||||
}),
|
||||
new Promise((resolve) => {
|
||||
setTimeout(
|
||||
() =>
|
||||
resolve({
|
||||
status: "failing",
|
||||
message:
|
||||
options.timeoutMessage || `Timeout trying to check port ${port}`,
|
||||
}),
|
||||
options.timeout ?? 1_000,
|
||||
)
|
||||
}),
|
||||
])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user