fix: high cpu usage

This commit is contained in:
Andras Bacsai 2022-08-25 10:28:32 +02:00
parent db16a357e8
commit c53f0dbb30
2 changed files with 27 additions and 9 deletions

View File

@ -107,11 +107,11 @@ fastify.listen({ port, host }, async (err: any, address: any) => {
await scheduler.start('cleanupPrismaEngines'); await scheduler.start('cleanupPrismaEngines');
await scheduler.start('checkProxies'); await scheduler.start('checkProxies');
// setInterval(async () => { setInterval(async () => {
// if (!scheduler.workers.has('deployApplication')) { if (!scheduler.workers.has('deployApplication')) {
// scheduler.run('deployApplication'); scheduler.run('deployApplication');
// } }
// }, 2000) }, 2000)
// Check for update & if no build is running // Check for update & if no build is running
setInterval(async () => { setInterval(async () => {

View File

@ -5,6 +5,8 @@ import { checkContainer } from '../lib/docker';
(async () => { (async () => {
if (parentPort) { if (parentPort) {
try { try {
const { default: isReachable } = await import('is-port-reachable');
let portReachable;
const { arch } = await listSettings(); const { arch } = await listSettings();
// Coolify Proxy local // Coolify Proxy local
const engine = '/var/run/docker.sock'; const engine = '/var/run/docker.sock';
@ -20,8 +22,12 @@ import { checkContainer } from '../lib/docker';
command: `docker stop -t 0 coolify-haproxy && docker rm coolify-haproxy` command: `docker stop -t 0 coolify-haproxy && docker rm coolify-haproxy`
}) })
} }
portReachable = await isReachable(80, { host: 'localhost' })
console.log({ port: 80, portReachable })
if (!portReachable) {
await startTraefikProxy(localDocker.id); await startTraefikProxy(localDocker.id);
} }
}
// TCP Proxies // TCP Proxies
const databasesWithPublicPort = await prisma.database.findMany({ const databasesWithPublicPort = await prisma.database.findMany({
@ -42,9 +48,13 @@ import { checkContainer } from '../lib/docker';
command: `docker stop -t 0 haproxy-for-${publicPort} && docker rm haproxy-for-${publicPort}` command: `docker stop -t 0 haproxy-for-${publicPort} && docker rm haproxy-for-${publicPort}`
}) })
} }
portReachable = await isReachable(publicPort, { host: destinationDocker.remoteIpAddress || 'localhost' })
console.log({ publicPort, portReachable })
if (!portReachable) {
await startTraefikTCPProxy(destinationDocker, id, publicPort, privatePort); await startTraefikTCPProxy(destinationDocker, id, publicPort, privatePort);
} }
} }
}
const wordpressWithFtp = await prisma.wordpress.findMany({ const wordpressWithFtp = await prisma.wordpress.findMany({
where: { ftpPublicPort: { not: null } }, where: { ftpPublicPort: { not: null } },
include: { service: { include: { destinationDocker: true } } } include: { service: { include: { destinationDocker: true } } }
@ -61,9 +71,13 @@ import { checkContainer } from '../lib/docker';
command: `docker stop -t 0 haproxy -for-${ftpPublicPort} && docker rm haproxy-for-${ftpPublicPort}` command: `docker stop -t 0 haproxy -for-${ftpPublicPort} && docker rm haproxy-for-${ftpPublicPort}`
}) })
} }
portReachable = await isReachable(ftpPublicPort, { host: destinationDocker.remoteIpAddress || 'localhost' })
console.log({ ftpPublicPort, portReachable })
if (!portReachable) {
await startTraefikTCPProxy(destinationDocker, id, ftpPublicPort, 22, 'wordpressftp'); await startTraefikTCPProxy(destinationDocker, id, ftpPublicPort, 22, 'wordpressftp');
} }
} }
}
// HTTP Proxies // HTTP Proxies
const minioInstances = await prisma.minio.findMany({ const minioInstances = await prisma.minio.findMany({
@ -82,9 +96,13 @@ import { checkContainer } from '../lib/docker';
command: `docker stop -t 0 ${id}-${publicPort} && docker rm ${id}-${publicPort} ` command: `docker stop -t 0 ${id}-${publicPort} && docker rm ${id}-${publicPort} `
}) })
} }
portReachable = await isReachable(publicPort, { host: destinationDocker.remoteIpAddress || 'localhost' })
console.log({ publicPort, portReachable })
if (!portReachable) {
await startTraefikTCPProxy(destinationDocker, id, publicPort, 9000); await startTraefikTCPProxy(destinationDocker, id, publicPort, 9000);
} }
} }
}
} catch (error) { } catch (error) {