fix: Remove wrong/stuck proxy configurations
This commit is contained in:
@@ -119,7 +119,8 @@ export async function getApplicationWebhook({ projectId, branch }) {
|
||||
}
|
||||
export async function getApplicationById({ id }) {
|
||||
const body = await prisma.application.findFirst({
|
||||
where: { id }
|
||||
where: { id },
|
||||
include: { destinationDocker: true }
|
||||
});
|
||||
|
||||
return { ...body };
|
||||
|
||||
@@ -187,6 +187,59 @@ export async function reloadHaproxy(engine) {
|
||||
const host = getEngine(engine);
|
||||
return await asyncExecShell(`DOCKER_HOST=${host} docker exec coolify-haproxy kill -HUP 1`);
|
||||
}
|
||||
export async function checkProxyConfigurations() {
|
||||
const haproxy = await haproxyInstance();
|
||||
await checkHAProxy(haproxy);
|
||||
try {
|
||||
const stats: any = await haproxy.get(`v2/services/haproxy/stats/native`).json();
|
||||
for (const stat of stats[0].stats) {
|
||||
if (stat.stats.status === 'DOWN' && stat.type === 'server') {
|
||||
const {
|
||||
name,
|
||||
backend_name: backendName,
|
||||
stats: { lastchg }
|
||||
} = stat;
|
||||
const application = await db.getApplicationById(name);
|
||||
if (!application) {
|
||||
const transactionId = await getNextTransactionId();
|
||||
await haproxy
|
||||
.delete(`v2/services/haproxy/configuration/backends/${backendName}`, {
|
||||
searchParams: {
|
||||
transaction_id: transactionId
|
||||
}
|
||||
})
|
||||
.json();
|
||||
return await completeTransaction(transactionId);
|
||||
}
|
||||
const found = await checkContainer(application.destinationDocker.engine, name);
|
||||
if (!found) {
|
||||
const transactionId = await getNextTransactionId();
|
||||
await haproxy
|
||||
.delete(`v2/services/haproxy/configuration/backends/${backendName}`, {
|
||||
searchParams: {
|
||||
transaction_id: transactionId
|
||||
}
|
||||
})
|
||||
.json();
|
||||
return await completeTransaction(transactionId);
|
||||
}
|
||||
if (lastchg > 120) {
|
||||
const transactionId = await getNextTransactionId();
|
||||
await haproxy
|
||||
.delete(`v2/services/haproxy/configuration/backends/${backendName}`, {
|
||||
searchParams: {
|
||||
transaction_id: transactionId
|
||||
}
|
||||
})
|
||||
.json();
|
||||
await completeTransaction(transactionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
export async function configureProxyForApplication({ domain, imageId, applicationId, port }) {
|
||||
const haproxy = await haproxyInstance();
|
||||
await checkHAProxy(haproxy);
|
||||
|
||||
@@ -4,7 +4,12 @@ import * as buildpacks from '../buildPacks';
|
||||
import * as importers from '../importers';
|
||||
import { dockerInstance } from '../docker';
|
||||
import { asyncExecShell, createDirectories, getDomain, getEngine, saveBuildLog } from '../common';
|
||||
import { configureProxyForApplication, reloadHaproxy, setWwwRedirection } from '../haproxy';
|
||||
import {
|
||||
checkProxyConfigurations,
|
||||
configureProxyForApplication,
|
||||
reloadHaproxy,
|
||||
setWwwRedirection
|
||||
} from '../haproxy';
|
||||
import * as db from '$lib/database';
|
||||
import { decrypt } from '$lib/crypto';
|
||||
import { sentry } from '$lib/common';
|
||||
@@ -253,6 +258,7 @@ export default async function (job) {
|
||||
try {
|
||||
if (destinationDockerId && destinationDocker.isCoolifyProxyUsed) {
|
||||
saveBuildLog({ line: 'Proxy configuration started!', buildId, applicationId });
|
||||
await checkProxyConfigurations();
|
||||
await configureProxyForApplication({ domain, imageId, applicationId, port });
|
||||
if (isHttps) await letsEncrypt({ domain, id: applicationId });
|
||||
await setWwwRedirection(fqdn);
|
||||
|
||||
Reference in New Issue
Block a user