diff --git a/pkgs/api/_deploy.ts b/pkgs/api/_deploy.ts index 47de049..0853da4 100644 --- a/pkgs/api/_deploy.ts +++ b/pkgs/api/_deploy.ts @@ -163,6 +163,14 @@ export const _ = { await deploy.init(); const deploys = fs.readdirSync(dir(`/app/web/deploy`)); + if (g.main.process) { + setTimeout(() => { + if (g.main.process) { + g.main.process.kill(); + } + }, 500); + } + return { now: Date.now(), current: parseInt(deploy.config.deploy.ts), diff --git a/pkgs/prod.ts b/pkgs/prod.ts index e17e876..bf6cbf5 100644 --- a/pkgs/prod.ts +++ b/pkgs/prod.ts @@ -4,7 +4,15 @@ import exitHook from "exit-hook"; import { existsAsync } from "fs-jetpack"; import { dir } from "utils/dir"; import { checkPort, randomBetween } from "utils/ensure"; +import { g } from "utils/global"; +g.main = { + process: null as null | Subprocess, + restart: { + timeout: null as any, + }, +}; +const main = g.main; let port = 0; try { @@ -26,17 +34,13 @@ exitHook((signal) => { console.log(`Exiting with signal: ${signal}`); }); -const main = { - process: null as null | Subprocess, - restart: { - timeout: null as any, - }, -}; - console.log("Process Manager running at port:", port); if (process.env.DATABASE_URL) { - if (!(await existsAsync(dir("node_modules/.prisma"))) && process.env.DATABASE_URL) { + if ( + !(await existsAsync(dir("node_modules/.prisma"))) && + process.env.DATABASE_URL + ) { try { await Bun.write( dir("app/db/.env"), diff --git a/pkgs/utils/global.ts b/pkgs/utils/global.ts index 49c3976..bc6a27e 100644 --- a/pkgs/utils/global.ts +++ b/pkgs/utils/global.ts @@ -1,4 +1,4 @@ -import { Server, WebSocketHandler } from "bun"; +import { Server, Subprocess, WebSocketHandler } from "bun"; import { Logger } from "pino"; import { RadixRouter } from "radix3"; import { PrismaClient } from "../../app/db/db"; @@ -47,6 +47,12 @@ export const g = global as unknown as { log: Logger; firebaseInit: boolean; firebase: admin.app.App; + main: { + process: null | Subprocess; + restart: { + timeout: any; + }; + }; notif: { db: Database; };