From 71ce2eb0a7d0abb2be638c8d20e0f83730cade02 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 27 Jul 2022 13:11:46 +0000 Subject: [PATCH] fix: Only 1 ssh-agent is needed --- apps/api/src/lib/common.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index 79b22bce0..bd94e060c 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -482,7 +482,10 @@ export async function createRemoteEngineConfiguration(id: string) { const { sshKey: { privateKey }, remoteIpAddress, remotePort, remoteUser } = await prisma.destinationDocker.findFirst({ where: { id }, include: { sshKey: true } }) await fs.writeFile(sshKeyFile, decrypt(privateKey) + '\n', { encoding: 'utf8', mode: 400 }) // Needed for remote docker compose - await asyncExecShell(`eval $(ssh-agent -s) && ssh-add -q ${sshKeyFile}`) + const { stdout: numberOfSSHAgentsRunning } = await asyncExecShell(`ps ax | grep [s]sh-agent | wc -l`) + if (numberOfSSHAgentsRunning !== '' && Number(numberOfSSHAgentsRunning.trim()) == 0) { + await asyncExecShell(`eval $(ssh-agent -s) && ssh-add -q ${sshKeyFile}`) + } const config = sshConfig.parse('') const found = config.find({ Host: remoteIpAddress }) if (!found) {