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) {